Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Switches in a cell in a table view
-
Is there any way to put switches in a cell in a table view?
-
@techteej Yes. I've just made a SettingsSheet class that does that and reads/writes the settings from a plist embedded in the .py file You need to subclass ListDataSource and then you can build the cells yourself.
-
@tony There doesn't happen to be an easier way?
-
@techteej The documentation talks about implementing your own datasource from scratch and there's a few examples of that around. Hopefully though, it's simpler to just subclass the existing ListDataSource. Don't be put off, it's not too hard. There's only one method to override, the one that builds the row... and 2 lines to make the cell, 6 the switch.
-
@techteej Here's a little test harness that will let you run the class above... paste it after the class and move the import to the top. Of course you'll get an error if you switch the switches because there's no plist in this little harness... but if you see it working you might be encouraged...
import ui tv = ui.TableView() lds = SettingsSheetDataSource([{'setting' : 'Setting 1', 'value' : 'On'}, {'setting' : 'Setting 2', 'value' : 'On'}]) lds.tableview_can_delete = False tv.data_source = lds tv.row_height = 50 tv.allows_selection = False tv.present('sheet')
-
_swA()
throws AttributeError: 'NoneType' object has no attribute '_pl'.Also, setting the "value" to True or False instead of 'On' or 'Off' simplifies the logic.
-
@ccc Did you read the comment with the post... "Of course you'll get an error if you switch the switches because there's no plist in this little harness" ?
-
Ahh, Another instance of iietdpctep. Code fragments are suboptimal.