How to fire uibarbuttonitem click event programmatically

后端 未结 8 2294
旧时难觅i
旧时难觅i 2020-12-05 05:41

I have created a UIActionSheet

UIActionSheet * action = [[UIActionSheet alloc]initWithTitle:@\"\"
                                                       


        
相关标签:
8条回答
  • 2020-12-05 06:08

    Not knowing the current bar button item action you can invoke it this way:

    [barButtonItem.target performSelector:barButtonItem.action]
    

    This will however bring "unknown selector" compiler warning, but this may be worked around.

    0 讨论(0)
  • 2020-12-05 06:09

    For my case with RxCocoa I needed to provide a nil - object to the perform action otherwise it would crash with EXC_BAD_ACCESS:

    let button = sut.navigationItem.leftBarButtonItem!
    _ = button.target?.perform(button.action, with: nil)
    
    0 讨论(0)
提交回复
热议问题