我有 ViewController
,然后是两个不同的 ViewControllers
,它们扩展了主 ViewController
,一个用于 iPhone,另一个用于 iPad。
iPad 的ViewController
实例化一个单独的扩展UIView
并将其设置为自己的 View 。该 View 有一些按钮,我想将其选择器方法添加为主要 ViewController
中的一些方法。如何实现?
所以这是一种可视化的方法:
Main ViewController
| iPhone ViewController
| iPad ViewController
| Some UIView Class --> Button must invoke method in Main View Controller
编辑: 我根本不使用界面生成器。
最佳答案
你的问题有点令人困惑,但如果我理解的话,你可以使用这样的代码来设置按钮:
[button addTarget:yourObject action:@selector(yourMethod:) forControlEvents:UIControlEventTouchUpInside];
因此,您将 addTarget 设置为 MainViewController
的实例,并将 action 设置为您想在 中调用的任何方法>主视图 Controller
。只要您的方法接受 IBAction
,您也应该能够在 Interface Builder 中执行此操作。
关于iphone - 将选择器添加到 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10758926/