您的位置:首页 > 移动开发 > IOS开发

iOS中的push

2016-05-10 00:00 399 查看
在编程中,我们会遇到这种情况(如图):



在界面上有一个红色的UIView,

红色View上面有一个绿色的UIView,

绿色View上面有一个橙色的UIButton。

在这里,我们如果要点击Button,push到导航的下一页的话,因为Button不在UIViewController上,所以是push不到的,所以要运用下面的方法:

//Button的方法
- (void)btnAction
{
NSLog(@"哈哈");

NextViewController *nextVC = [[NextViewController alloc] init];
[self.viewController.navigationController pushViewController:nextVC animated:YES];
}

//Button方法中调用的方法
- (UIViewController *)viewController
{
UIResponder *next = self.nextResponder;
do {
if ([next isKindOfClass:[UIViewController class]]) {
return (UIViewController *)next;
}

next = next.nextResponder;
} while (next != nil);

return nil;
}

可以把这段代码做成一个类,使用的时候直接拖过去就行了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: