且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何访问超级视图控制器?

更新时间:2023-09-28 17:17:40

在你的辅助控制器中,尝试

In your secondary controller, try

id mainViewController = [self.view.superview nextResponder];

并检查这是否是您正在寻找的视图控制器.

and check if this is the view controller you're looking for.

Apple 的 -[UIResponder nextResponder] 文档:

Apple's documentation of -[UIResponder nextResponder]:

UIView 通过返回管理它的 UIViewController 对象(如果有)或它的超视图(如果没有)来实现这个方法

UIView implements this method by returning the UIViewController object that manages it (if it has one) or its superview (if it doesn’t)