有時我們會遇到一些比較特別的需求,比如跳轉(zhuǎn)到一個功能頁面的時候,我們不需要顯示第一個頁面,需要顯示中間的某個頁面(比如第二頁),比較常見的就是微信中的選擇照片的時候,點(diǎn)擊從手機(jī)相冊選擇顯示的是相機(jī)膠卷頁面,點(diǎn)擊返回才是照片頁面
其實(shí)是個很簡單的功能,我們在這里記錄一下
首先我們要創(chuàng)建自己的LJBaseNavigationViewController類,這個類繼承于UINavigationController,然后我們創(chuàng)建一個init方法用于初始化這個類,重點(diǎn)就在這個方法里面
- (instancetype)initWithOtherDisplay {
//根視圖
FirstViewController *first = [[FirstViewController alloc]init];
self = [super initWithRootViewController:first];
//第二個視圖
TwoViewController *two = [[TwoViewController alloc]init];
[self pushViewController:two animated:YES];
return self;
}
從上面的方法里面可以看出,需要根據(jù)根視圖創(chuàng)建NavigationController之后,及時的push你所需要顯示的視圖(測試了一下,push兩次也可以)
外面調(diào)用這個類
LJBaseNavigationViewController *base = [[LJBaseNavigationViewController alloc]initWithOtherDisplay];
[self presentViewController:base animated:YES completion:^{
}];