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.


    TableView Button Color

    Pythonista
    2
    2
    1558
    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.
    • Maxmad68
      Maxmad68 last edited by

      Hello,
      I would like to know how can I change the color of the "Delete" button which appears when we swipe a row in a ui.TableView ?
      The purpose is to change the color, the title and the action of that button for some rows
      Is it possible with objc_util ?
      Thanks

      (Sorry for my bad english, I'm a french 16 years old boy)

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

        Hi,

        here's the example how to use UITableViewRowAction for this purpose.

        #!python3
        
        import ui
        from objc_util import *
        
        #
        # UITableViewDelegate
        #
        
        def handler(_cmd, action, index_path):
        	print('Trash it!')
        
        block_handler = ObjCBlock(handler, restype=None, argtypes=[c_void_p, c_void_p, c_void_p])		
        
        def tableView_editActionsForRowAtIndexPath_(self, cmd, table_view, index_path):
        	yellow = ObjCClass('UIColor').yellowColor()
        	
        	action = ObjCClass('UITableViewRowAction').rowActionWithStyle_title_handler_(0, ns('Trash it!'), block_handler)
        	action.setBackgroundColor(yellow)
        
        	return ns([action]).ptr
        
        
        def make_table_view_delegate():
        	methods = [tableView_editActionsForRowAtIndexPath_]
        	protocols = ['UITableViewDelegate']
        	delegate = create_objc_class('CustomTableViewDelegate', methods=methods, protocols=protocols)
        	return delegate.alloc().init()
        
        #
        # UITableView
        #
        
        table_view = ui.TableView(name='Custom Action', frame=(0, 0, 300, 480))
        table_view.data_source = ui.ListDataSource(['Hallo', 'Hi', 'Ciao'])
        
        table_view_objc = ObjCInstance(table_view)
        table_view_objc.setDelegate(make_table_view_delegate())
        
        table_view.present('sheet')
        
        1 Reply Last reply Reply Quote 1
        • First post
          Last post
        Powered by NodeBB Forums | Contributors