![](/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.