get UIView's viewcontroller (iphone)

后端 未结 2 594
时光说笑
时光说笑 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 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)"

提交回复
热议问题