• ryubai

    @cvp thank you very much.
    i prefer to use uitableviewcontroller,it connect data source and delegate automatically.
    your code works but when I transfer to UITableViewController,it crashs.

    posted in Pythonista read more
  • ryubai

    @cvp i don’t understand how to .. i want to subclass a UITableViewcontroller and add a action when i left swipe a cell.
    could you show me the right way in the code i provided?
    sorry for my poor understanding.

    posted in Pythonista read more
  • ryubai

    @cvp i try the code below,but still crash,what’s the problem?

    from objc_util import *
    import ui
    
    @on_main_thread
    def main_tableview():
        def tableView_numberOfRowsInSection_(_self, _cmd,_tv,_section):
            return 3
        
        def numberOfSectionsInTableView_(_self, _cmd,_tv):
            return 1
        
        def tableView_cellForRowAtIndexPath_(_self, _cmd,_tv,_indexpath):
            cell=ObjCInstance(_tv).dequeueReusableCellWithIdentifier("cell1") 
            if cell==None:
                cell=ObjCClass('UITableViewCell').alloc().initWithStyle_reuseIdentifier_(3,"cell2")
            
            cell.textLabel().text = 'test'
            return cell.ptr
        
        def tableView_trailingSwipeActionsConfigurationForRowAtIndexPath_(_self,_cmd,_tv,_indexPath): 
            return None
            
        tvc1 = create_objc_class('UITableViewController',ObjCClass('UITableViewController'),methods=[tableView_numberOfRowsInSection_,numberOfSectionsInTableView_,tableView_cellForRowAtIndexPath_,tableView_trailingSwipeActionsConfigurationForRowAtIndexPath_])
        
        return  tvc1.alloc().init().autorelease()   
        
    @on_main_thread
    def main():
    
        root_vc = UIApplication.sharedApplication().keyWindow().rootViewController()
        tbc=main_tableview()
        root_vc.presentViewController_animated_completion_(tbc, True, None)
        
    if __name__=='__main__':
        main()
    

    posted in Pythonista read more
  • ryubai

    @cvp when i comment # return none,i got it.
    thanks very much.

    posted in Pythonista read more
  • ryubai

    @cvp thanks

    i have checked _objc_exception.txt and saw nothing in this crash.
    try the example you provided,when i do a left swipe,it just show “delete” button.
    i have no idea how the code below work

        # set actions if swipe
        UIContextualAction = ObjCClass('UIContextualAction').alloc()
        UIContextualAction.setTitle_("Drizzel's action 😅")
        # block does not have parameter nor return, thus we can use a Python def
        UIContextualAction.setHandler_(handler)
        UIContextualAction.setBackgroundColor_(ObjCClass('UIColor').blueColor().colorWithAlphaComponent(0.5))
        
        UISwipeActionsConfiguration = ObjCClass('UISwipeActionsConfiguration').configurationWithActions_([UIContextualAction])

    posted in Pythonista read more
  • ryubai

    hey~i need to return none in a objc new class function,but it crash’s when i use return none.how can i solve it? thanks very much.

    def tableView_trailingSwipeActionsConfigurationForRowAtIndexPath_(_self,_cmd,_tv,_indexPath):       
            return None
    

    posted in Pythonista read more
  • ryubai

    @JonB

    thanks.
    it seems not convenient for debug, and i still use objc_util as OC bridge.

    posted in Pythonista read more
  • ryubai

    @JonB

    run more than once will raise such errs,then how to solve?

    ctypes_patch.make_callback_returnable(CGSize)
    File "/private/var/mobile/Containers/Shared/AppGroup/02422888-CC52-45FC-BB53-72013D3F4AFA/Pythonista3/Documents/site-packages/ctypes_patch.py", line 128, in make_callback_returnable
    raise ValueError("The ctype {} already has a getfunc")
    ValueError: The ctype {} already has a getfunc

    posted in Pythonista read more
  • ryubai

    latest when i try rubicon_objc.
    the code below, run once is normal. run anther time will raise a err.
    how can i solve it? thanks in advance

    RuntimeError: An Objective-C class named b'Handler' already exists

    code:

    from rubicon.objc import NSObject, objc_method

    class Handler(NSObject):
    @objc_method
    def initWithValue_(self, v: int):
    self.value = v
    return self

    @objc_method
    def pokeWithValue_andName_(self, v: int, name) -> float:
        print("My name is", name)
        return v / 2.0
    

    my_handler = Handler.alloc().initWithValue(42)

    posted in Pythonista read more
  • ryubai

    @JonB @mikael @cvp and other dear friends

    Sincerely,many thanks to you all!
    i love to stay here.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!