如何使用选择器调用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:)";
答案 0 :(得分:0)
closeBarButtonItem.action = "close:"
func close(sender: UIButton!) {
self.dismissViewControllerAnimated(true, completion: nil)
}
答案 1 :(得分:0)
没有直接的方法可以做到这一点,因为如果您使用@selector(dismissViewControllerAnimated:completion:)
,则会使用sender
而不是动画BOOL和event
而不是{{}调用它1}}阻止。这些都不是有效的参数。
如果你想缩短你的代码,你应该使用completion handler
库,这将允许你添加事件处理程序直接控制。这是一个Objective-C库,因此可以通过JTTargetActionBlock
示例(尚未测试):
Voice-Bridging-Header