簡體   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