本文共 1338 字,大约阅读时间需要 4 分钟。
共同点
– present和push方法都可用于推出新的界面。 present和dismiss对应使用,push和pop对应使用。不同点
– present弹出的视图是模态视图(我对模态视图的理解大概就是一个临时视图);push由视图栈控制,每一个视图都入栈,调用之前的视图则需要出栈 – present只能逐级返回;push可返回任意一层使用UINavigationController时使用push方法: 例如:[self.navigationController pushViewController:xxx animated:NO];
返回时用pop: 例如:[self.navigationController popViewControllerAnimated:NO];其他时候用present方法: 例如:[self presentViewController:xxx animated:NO completion:nil]; ;
返回时用dismiss: 例如:[self dismissViewControllerAnimated:NO completion:nil];为了在B视图里能push,我给B视图创建了一个导航栏,A视图 present进去
A视图按钮的点击事件:- (void)pass { NSLog(@"press1"); FirstViewController *first = [[FirstViewController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:first]; [self presentViewController:nav animated:NO completion:nil];}
B视图push到C视图
B视图按钮的点击事件:- (void)pass { NSLog(@"press2"); SecondViewController *second = [[SecondViewController alloc] init]; [self.navigationController pushViewController:second animated:NO];}
- (void)back { NSLog(@"back"); [self dismissViewControllerAnimated:NO completion:nil];}
C视图:
点击back后: 直接返回到了A视图!- (void)back { NSLog(@"back"); [self.navigationController popViewControllerAnimated:NO];}
点击back后:
则返回到了B视图!转载地址:http://owkti.baihongyu.com/