答案如下:
[[self superview ].nextResponder
[[[self superview ] nextResponder]
[self.nextResponder method];
上面的都可以,看情况使用,使用的时候最好判断一下。
官方解释
UIView implements this method by returning the UIViewController object that manages it (if it has one) or its superview (if it doesn’t); UIViewController implements the method by returning its view’s superview; UIWindow returns the application object, and UIApplication returns nil.
即如下代码可以进行判断:
id next = [self nextResponder];
while(![next isKindOfClass:[ViewController class]])//这里跳不出来。。。有人说这里跳不出来,其实是因为它没有当前这个view放入ViewController中,自然也就跳不出来了,会死循环,使用时需要注意。
{
next = [next nextResponder];
}
if ([next isKindOfClass:[ViewController class]])
{
controller = (ViewController *)next;
}