get UIView's viewcontroller (iphone)

后端 未结 2 592
时光说笑
时光说笑 2021-02-08 19:38

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 v

相关标签:
2条回答
  • 2021-02-08 19:53

    you can use

    [yourUIView.window.rootViewController doSomething]
    
    0 讨论(0)
  • 2021-02-08 20:07

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

    0 讨论(0)
提交回复
热议问题