- 定义区别
- pushViewController 导航控制器入栈的方式切换页面
- presentViewController 模态切换的方式切换页面
- 返回方法
- 用 UINavigationController 的时候用 pushViewController:animated
返回之前的视图 [[self navigationController] popViewControllerAnimated:YES];
push 以后会在 navigation的 left bar自动添加back按钮,它的响应方法就是返回,所以一般不需要写返回方法,点back按钮即可 - 其他时候用presentModalViewController:animated
[self presentModalViewController:controller animated:YES];
返回之前的视图 [self dismissModalViewControllerAnimated:YES];
- 用 UINavigationController 的时候用 pushViewController:animated
- 使用区别
- 如果比作英语语法的话,就是说[self presentModalViewController:controller animated:YES];的主语是UIVIewController所以是在单纯页面切换
- 而用到[self.navigationController pushViewController:upViewController animated:YES];与[self.navigationController popViewControllerAnimated:YES];这两句时主语是navigationController,所以如果是在导航栏上实现页面的跳转使用push,除此之外的都是用present
- 参考文章
push与present区别与使用
猜你喜欢
转载自blog.csdn.net/KevinAshen/article/details/81389085
今日推荐
周排行