繁体   English   中英

UIButton addtarget到另一个视图控制器

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM