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.


    Add detail text label

    Pythonista
    sqlite tableview detail text lab
    2
    3
    1678
    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.
    • Rufat
      Rufat last edited by

      Hi, I’m trying to add detail text label, and can’t to create it on each row, I guess problem is in this row type = {0: ‘subtitle, i: ‘subtitle’} Can’t create loop for each row
      import ui
      import sqlite3 as db

            conn = db.connect('pythonsqlite.db')
            conn.row_factory = lambda cursor, row: row[0]
            c = conn.cursor()
            ids = c.execute('SELECT name FROM Names').fetchall()
            ids1 = c.execute('SELECT surname FROM Names').fetchall()
            me = ids1
      
             for i in range (len(ids)):
      		print(i)
      
             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 len(ids)
      
      def tableview_cell_for_row(self, tableview, section, row):
      	# Create and return a cell for the given section/row
      
      			
      	type = {0: 'subtitle', i: 'subtitle'}[row]
      	
      	self.data = ids
      	self.data1 = me
      	self.cells = [ui.TableViewCell(type)
                        for _ in range(len(self.data))]
      	cell = self.cells[row]
      	cell.text_label.text = self.data[row]
      	cell.detail_text_label.text = self.data1[row]
      	return cell
      
      def tableview_title_for_header(self, tableview, section):
      	# Return a title for the given section.
      	# If this is not implemented, no section headers will be shown.
      	return ('Names')
      
      
      def tableview_delete(self, tableview, section, row):
      	# Called when the user confirms deletion of the given row.
      	pass
      
      def tableview_move_row(self, tableview, from_section, from_row, to_section, to_row):
      	# Called when the user moves a row with the reordering control (in editing mode).
      	pass
      

      v = ui.load_view('MyForm')
      #v['tableview1'].background_color = 'yellow'
      v['tableview1'].data_source=MyTableViewDataSource()
      v.present('sheet')

      mikael 1 Reply Last reply Reply Quote 0
      • mikael
        mikael @Rufat last edited by

        @Rufat, no need for you to loop:

        import ui
        
        ids = ['one', 'two', 'three']
        details = ['sample', 'in', 'view']
        
        
        class MyTableViewDataSource:
        
            def tableview_number_of_rows(self, tableview, section):
                return len(ids)
        
            def tableview_cell_for_row(self, tableview, section, row):
                cell = ui.TableViewCell('subtitle')
                cell.text_label.text = ids[row]
                cell.detail_text_label.text = details[row]
                return cell
        
        
        tv = ui.TableView()
        tv.data_source = MyTableViewDataSource()
        tv.present('fullscreen')
        
        1 Reply Last reply Reply Quote 0
        • Rufat
          Rufat last edited by

          Thank you!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors