gpt4 book ai didi

ios - 调用 Selector 到 DismissViewController

转载 作者:行者123 更新时间:2023-11-28 08:56:09 25 4
gpt4 key购买 nike

如何使用选择器调用 self.dismissViewControllerAnimated(true, completion: nil);

    //MARK - closeBarButtonItem
closeBarButtonItem = UIBarButtonItem();
closeBarButtonItem.image = UIImage(named: "closeIcon");
closeBarButtonItem.target = self;

我已经尝试了下面的选择器,但它一直崩溃说找不到选择器

    //NO SELECTOR FOUND CRASH
closeBarButtonItem.action = "dismissViewControllerAnimated::";

//NO SELECTOR FOUND CRASH
closeBarButtonItem.action = "dismissViewControllerAnimated:true:";

//NO SELECTOR FOUND CRASH
closeBarButtonItem.action = "dismissViewControllerAnimated:completion:";

//NO SELECTOR FOUND CRASH
closeBarButtonItem.action = Selector("dismissViewControllerAnimated::");

//NO SELECTOR FOUND CRASH
closeBarButtonItem.action = Selector("dismissViewControllerAnimated:true:)";

//NO SELECTOR FOUND CRASH
closeBarButtonItem.action = Selector("dismissViewControllerAnimated:completion:)";

最佳答案

没有直接的方法来做到这一点,因为如果你使用 @selector(dismissViewControllerAnimated:completion:),它会被 sender 调用而不是动画BOOL 和 event 而不是 completion handler block 。这些不是有效的论点。

如果你想缩短你的代码,你应该使用JTTargetActionBlock库,它允许你直接添加事件处理程序来控制。这是一个 Objective-C 库,所以用户可以通过 Voice-Bridging-Header

使用它

示例(尚未测试):

closeBarButtonItem.addEventHandler({(sender, event) in
self.dismissViewControllerAnimated(true, completion: nil)

}, forControlEvent: UIControlEventTouchUpInside)

关于ios - 调用 Selector 到 DismissViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32989126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com