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.


    ui.tableview does not update screen

    Pythonista
    2
    4
    2375
    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.
    • tomkirn
      tomkirn last edited by

      Hi all,

      I run in a problem that a ui.tableview does not update the screen after changing the content. Only after moving/scrolling the ui.tableview up and down the new content will be shown.

      The code is only for demo, i real I get the content from sqlite and try to update after filtering. UI has only "tableview1" and "button1".

      # coding: utf-8
      
      import ui
      
      def buttonaction(sender):
      Liste = []
      for i in range(20,30):
      	Liste.append('Neu-Kram '+str(i))
      lst = ui.ListDataSource(Liste)
      v['tableview1'].data_source = lst
      v['tableview1'].reload
      v['tableview1'].set_needs_display()
      v.set_needs_display()
      
      def init():
      Liste = []
      for i in range(1,10):
      	Liste.append('Kram '+str(i))
      lst = ui.ListDataSource(Liste)
      v['tableview1'].data_source = lst
      
      
      v = ui.load_view()
      
      init()
      v['button1'].action = buttonaction
      v.present('sheet')
      

      Any hints what I am doing wrong?

      Regards
      Tom

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

        Change v['tableview1'].reload to v['tableview1'].reload().

        The parenthisis at the end will cause the function to be called and then magic will happen.

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

          Sometimes its so easy..... Thanks a lot!

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

            Another approach is to replace the .data_source.items and then you do not even need to call reload().

            # coding: utf-8
            
            import ui
            
            def init():
                Liste = ['Kram {}'.format(i) for i in xrange(1,10)]
                v['tableview1'].data_source.items = Liste
            
            def buttonaction(sender):
                Liste = ['Neu-Kram {}'.format(i) for i in xrange(20,30)]
                v['tableview1'].data_source.items = Liste
            
            v = ui.load_view()
            init()
            v['button1'].action = buttonaction
            v.present('sheet')
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors