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.


    Extra header row added to tableview when I add subviews to the cells.

    Pythonista
    2
    3
    2908
    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.
    • simonh
      simonh last edited by

      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()
      
      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        There isn't really any extra header view, your label frames are just incorrect for some reason and overlap with the next cell (not quite sure why right now)... Try adding something like label.frame = cell.bounds before you add the label to the cell.

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

          That does the trick in the example. I can't use it directly in the real code because I'm putting several labels into the cell, but it should just be a matter of calculating the required frame geometries for the labels. Thanks!

          • update. The workaround works fine for my use case. I set the label frame to the cell bounds, then offset .x and .width as required. Looks perfect!
          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors