omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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?

    Pythonista
    3
    4
    2732
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • metawops
      metawops last edited by

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

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        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.

        1 Reply Last reply Reply Quote 2
        • omz
          omz last edited by

          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.

          1 Reply Last reply Reply Quote 2
          • metawops
            metawops last edited by

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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors