我有BaseViewController
,它是UIViewController
的子类,然后我有这个LeftViewController
和RightViewController
,它们是BaseViewController
的子类。我想创建一个函数来创建从 BaseViewController
声明的导航栏按钮项,以便我可以从子级访问。
问题是,为了设置每个 navbaritem 的操作/选择器,如何将 subview Controller 作为参数传递给该函数?有些选择器只是在 LeftViewController
中声明,或者仅在 RightViewController
中声明,因此编译器会提示未声明的选择器。
谢谢。
最佳答案
在BaseviewController选择器方法中,您可以使用关键字self来获取Childviewcontroller,因为应用了运行时多态性,您可以使用self作为
if self.isKindOfClass(RightViewController.classForCoder()) {
let controller: RightViewController = self as! RightViewController
}
关于ios - 使用 UIViewController 子类作为参数设置按钮目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37206693/