开发者

get UIView's viewcontroller (iphone)

I've done this to get the view:

[self.superview viewWithTag:10]

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 viewc开发者_开发知识库ontroller. eg:

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

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


You can use the -nextResponder method to do it:

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

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)"


you can use

[yourUIView.window.rootViewController doSomething]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜