How to get UIViewController of a UIView's superview in iOS?
You can't access it directly, but you can find the next view controller (if any) by traversing the responder chain.
This is how the Three20 framework does it:
- (UIViewController*)viewController
{
for (UIView* next = [self superview]; next; next = next.superview)
{
UIResponder* nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]])
{
return (UIViewController*)nextResponder;
}
}
return nil;
}