nvedwards
Nov 11, 2019 - 07:39
I’m trying to populate a tableview with the contents of a dictionary. i want the tableview data to be grouped by sections following the rows belonging to each section. Below is the code that i put together so far. The keys show up in the tableview but not the values. How do you populate the rows/cells of each section with the key values?
Thanks!
import ui
def load_table(view):
#data = ['spam', 'ham', 'egg']
# Sections and section rows
data = {'meat': ['spam', 'ham'], 'fruit': ['apple', 'orange']}
datasource = ui.ListDataSource(data)
view['tv_food'].data_source=datasource
view['tv_food'].delegate=datasource
def main():
view = ui.load_view('tableview_test') # tableview from designer
load_table(view)
nav = ui.NavigationView(view)
nav.present()
if __name__ == '__main__':
main()