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.
Closing view from enclosed TableView's delegate?
-
Got a ui View.
It contains a TableView and nothing else.
The view gets presented viapresent('sheet')
.
Immediately after presenting it I wait viawait_modal()
.
Now the user should tap on one item in the TableView and the view should close.
The closing of the view works (tableview.superview.close()
) but I don't know how to transport the information about the tapped row back to the main thread so that I can work with it after thewait_modal()
returns ...?This is my delegate (with debug output):
class MyTableViewDelegate (object): def tableview_did_select(self, tableview, section, row): # Called when a row was selected. print("tableview_did_select: row=", row) print(tableview.data_source.items[row]) tableview.superview.close() pass
Any help regarding how to get the
tableview.data_source.items[row]
information out of this delegate method back to my main program would be awesome! 😀 -
When the view is closed, tableview.selected_row should, I think, still work. So you could use v['tableview1'].selected_row, assuming you give your tableview the name property of 'tableview1'.
If not, just set a an attribute in your main view from the delegatesuperview.selected_row= tableview.selected_row
(assuming your delegate first argument is named tableview)
Check out the dialogs module source for more examples and ideas.
-
If your UI is really just a table view, and you don't need anything fancy in the rows, you might want to consider using
dialogs.list_dialog()
instead. Might be a more straight-forward option, depending on your use case. -
Aweseom hints, guys! Didn't know about the dialogs module at all. The
dialogs.list_dialog()
looks good and suits my needs. 😀
Thanks a lot!!