Forum Archive

ui.tableview does not update screen

tomkirn

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

ccc

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.

tomkirn

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

ccc

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')