![](/img/trans.png)
[英]how to validate from UIButton addtarget to a different view controller
[英]UIButton addtarget to a different view controller
我在另一个ViewController
上的view
添加一个button
。 我需要目标选择器指向该视图控制器:
//target is self which works only works where I created the button
testBTN.addTarget(self, action: "test:", forControlEvents: UIControlEvents.TouchUpInside)
//otherVC is being instantiated as a new view controller so it doesn't work
testbtn.addTarget(otherVC(), action: "test:", forControlEvents: UIControlEvents.TouchUpInside)
我怎样才能使目标指向一个已经存在的ViewController
(otherVC)?
弄清楚了
let otherVC = self.storyboard!.instantiateViewControllerWithIdentifier("otherIdentifier")
testbtn.addTarget(otherVC, action: "test:", forControlEvents: UIControlEvents.TouchUpInside)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.