得到UIView的viewcontroller(iphone) [英] get UIView's viewcontroller (iphone)

查看:123
本文介绍了得到UIView的viewcontroller(iphone)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样做是为了获得视图:

I've done this to get the view:

[self.superview viewWithTag:10]

但是如何获得该视图的viewcontroller。就像你可以获得viewcontroller的视图一样,我想转向其他方式,这样我就可以向该viewcontroller发送一条消息(调用一个方法)。例如:

But how can I get that view's viewcontroller. Just like you can get the the viewcontroller's view I want to go the other way so I can send a message (call a method) to that viewcontroller. eg:

[[self.superview viewWithTag:10].viewController doSomething];

(显然不是实际的代码,但我想要这样的东西)

(obviously that not actual code but I want something like that)

推荐答案

您可以使用 -neResponder 方法来执行此操作:

You can use the -nextResponder method to do it:

[(YourUIViewController *)[[self.superview viewWithTag:10] nextResponder] doSomething];

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

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的viewcontroller(iphone)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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