gpt4 book ai didi

ios - UIButton 将目标添加到不同的 View Controller

转载 作者:行者123 更新时间:2023-11-28 12:57:26 26 4
gpt4 key购买 nike

我正在向不同 ViewController 上的 view 添加一个 button。我需要目标选择器指向那个 View Controller :

//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)

关于ios - UIButton 将目标添加到不同的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34687044/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com