Forum Archive

Closing view from enclosed TableView's delegate?

metawops

Got a ui View.
It contains a TableView and nothing else.
The view gets presented via present('sheet').
Immediately after presenting it I wait via wait_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 the wait_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! 😀

JonB

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 delegate

superview.selected_row= tableview.selected_row

(assuming your delegate first argument is named tableview)

Check out the dialogs module source for more examples and ideas.

omz

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.

metawops

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!!