simonh
Feb 24, 2015 - 21:19
Heres a code sample. If you comment out the three lines creating and adding the label the view looks fine. I need to add subviews because I'm trying to create a grid-style table of labels and values.
import ui
class MyTableViewDataSource (object):
def tableview_number_of_sections(self, tableview):
# Return the number of sections (defaults to 1)
return 1
def tableview_number_of_rows(self, tableview, section):
# Return the number of rows in the section
return 3
def tableview_cell_for_row(self, tableview, section, row):
# Create and return a cell for the given section/row
cell = ui.TableViewCell()
#cell.text_label.text = 'Foo Bar' # uncomment to switch behaviours
label = ui.Label() # comment out to switch behaviour
label.text = 'mylabel' # comment out to switch behaviour
cell.add_subview(label) # comment out to switch behaviour
return cell
data_source = MyTableViewDataSource()
tv = ui.TableView()
tv.data_source = data_source
mv = ui.View()
mv.add_subview(tv)
mv.present()