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.


    Refreshing/Replacing Tableview Data

    Pythonista
    3
    7
    4876
    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.
    • cook
      cook last edited by

      I'm wondering if anyone has a suggestion for how to refresh the data for a tableview and for it to display!

      I have a UI with a search bar, and the resulted list is displayed in a tableview. The textfield (search bar) action just runs the function to get new data, then run through my datasource class for the tableview. I know that everything works as I've tested it without the search bar action, but that is I believe where the problem is.

      I've tried tableview.refresh() and tableview.refresh_data() in my action function to no avail.

      I've never tried to do something like this, so I'm not sure exactly how it should work. I know how to get initial data displayed in a tableview, but replacing it entirely with different data via a function ....?

      Thanks guys always for your help!

      Phuket2 2 Replies Last reply Reply Quote 0
      • Phuket2
        Phuket2 @cook last edited by

        @cook , just guessing but I think you need to use TableView.reload or TableView.reload_data

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

          Whoops sorry in my post above I meant to have reload/reload_data

          1 Reply Last reply Reply Quote 0
          • shaun-h
            shaun-h last edited by

            @Phuket2 is right reload_data should do it. I use it in a few scripts I've written can you post the code you are trying to do it?

            1 Reply Last reply Reply Quote 0
            • shaun-h
              shaun-h last edited by

              I have actually created you a very poor example of reloading data, click the add and type some text to try it out

              # coding: utf-8
              import ui
              import dialogs
              
              class tv (object):
              	def __init__(self):
              		self.data = []
              		
              	def tableview_did_select(self, tableview, section, row):
              		pass
              		
              	def tableview_number_of_sections(self, tableview):
              		return 1
              
              	def tableview_number_of_rows(self, tableview, section):
              		return len(self.data)
              		
              	def tableview_cell_for_row(self, tableview, section, row):
              		cell = ui.TableViewCell()
              		cell.text_label.text = self.data[row]
              		return cell
              
              data = tv()
              v = ui.TableView()
              def add(sender):
              	data.data.append(dialogs.input_alert(title='Please Enter'))
              	v.reload_data()
              if __name__ == '__main__':
              	
              	v.right_button_items = [ui.ButtonItem(title='Add',action=add)]
              	v.data_source = data
              	v.delegate = data
              	v.present()
              
              1 Reply Last reply Reply Quote 1
              • cook
                cook last edited by

                @shaun-h , @Phuket2 thanks for your help... I have it working now. It was a silly mistake in how I changed the data.

                I saw clearly from Shaun-h's example that I was changing the data in the class wrong.

                I was doing something like data_source = Tv(data) rather than data_source.data = data

                Much obliged!

                1 Reply Last reply Reply Quote 1
                • Phuket2
                  Phuket2 @cook last edited by

                  @cook , look for something very simple. Normally it just works for me. But I have also made simple mistakes. When I look for a complicated explanation, I often miss a mis spelling etc, that passes as being valid

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