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.
TableViewCell.detail_text_label
-
I want to use the
detail_text_label
on aTableViewCell
but the documentation says that it's only accessible in non-default styles of theTableViewCell
class, so my question is: How do I change the style of the cell? -
I'm sorry that this isn't documented properly. When you initialize a
TableViewCell
, you can pass the style as a string, e.g.my_cell = ui.TableViewCell('subtitle')
. Valid values for thestyle
parameter are'default'
(same as when you leave out the parameter),'subtitle'
,'value1'
and'value2'
(the last two are commonly used for settings). -
Thanks for the help! To try this out I made a little test code to show the different types if anyone else wants to use this.
import ui class source (object): def tableview_number_of_rows(self, tv, s): return 4 def tableview_cell_for_row(self, tv, s, r): type = {0:'default', 1:'subtitle', 2:'value1', 3:'value2'}[r] cell = ui.TableViewCell(type) cell.text_label.text = 'Title' try: cell.detail_text_label.text = 'Detail' except AttributeError: pass try: cell.image_view.image = ui.Image.named('ionicons-image-32') except AttributeError: pass return cell view = ui.TableView() view.data_source = source() view.present()
Not very elegant but it helps.
-
Very nice, thank you.
-
That's an awesome feature, this needs to be in the documentation! ;)
@Omega0, your test code is quite useful as a quick reference for how the different styles look, thanks for sharing it.
-
I was wondering the exact same thing as @Omega0 did two years ago. Since the documentation has not yet been updated it's great to have this forum and that it is easy to search.
-
Nice code. I changed it to replace line 14 ( pass) with print('Detail error ', r, type) and line 18 (pass) with print('Image error', r, type). This showed that you cannot use cell.detail_text_label.text when type='default'. And you cannot use cell.image__view.image when type = 'value2'.