我在另一个button
上向view
添加了ViewController
。我需要目标选择器指向该视图控制器:
//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)?
答案 0 :(得分:2)
想通了
let otherVC = self.storyboard!.instantiateViewControllerWithIdentifier("otherIdentifier")
testbtn.addTarget(otherVC, action: "test:", forControlEvents: UIControlEvents.TouchUpInside)