push:
第一种方式:
通过故事板
id vc=[self.storyboard instantiateViewControllerWithIdentifier:@"CartVC"];
[self.navigationController pushViewController:vcanimated:YES];
第二种方式:
通过实例化一个新界面
[self.navigationController pushViewController:[[CartViewController alloc]init] animated:YES];
推荐使用第一种,因为第一种push的是以前的界面(如果有的话),第二种是新建的页面,而且每push一次,新建一个。
第三种方式:
没有navigationController的情况下
UIStoryboard *View = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
BrowseImageViewController *destination = [View instantiateViewControllerWithIdentifier:@"BrowseImageVC"];
destination.exhibitionType=pExhibitionType;
[self presentViewController:destination animated:YES completion:nil];
pop:
返回最底层的界面:
[self.navigationController popToRootViewControllerAnimated:YES];
把想删除的 VC 从 viewControllers 里去掉,把你要加入的 VC 添加进去,用这种方法来代替 push:
NSMutableArray *arr =self.navigationController.viewControllers.mutableCopy;
/* 删除不需要的VC */
[arrremoveObject:self];
/* 添加要显示的VC */
self.navigationController.viewControllers = arr;