如何通过代码从 UIView 获取 UIViewController [英] How to get a UIViewController from a UIView via code

查看:24
本文介绍了如何通过代码从 UIView 获取 UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从 UIView 对象获取视图控制器引用?我需要这样的东西:

There is a way to get a view controller reference from a UIView object? I need something like this:

MyParentViewController *myParentViewController = [self.view.superview controller];

推荐答案

您可以使用 -nextResponder 方法来完成.根据 http://developer.apple.com/library/ios/documentation/uikit/reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/instm/UIResponder/nextResponder , "UIView 实现此方法通过返回管理它的 UIViewController 对象(如果有)或它的超视图(如果没有)"

You can use the -nextResponder method to do it. According to http://developer.apple.com/library/ios/documentation/uikit/reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/instm/UIResponder/nextResponder , "UIView implements this method by returning the UIViewController object that manages it (if it has one) or its superview (if it doesn’t)"

这篇关于如何通过代码从 UIView 获取 UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆