(一)使用NavigationViewController進行頁面跳轉(zhuǎn)時,應(yīng)該使用pushViewController方法來跳轉(zhuǎn)至下一頁面户矢,這樣的話,下一頁面同樣在NavigationViewController容器中。
1谴忧、跳轉(zhuǎn)到下一頁面:
PowerViewController*power = [[PowerViewControlleralloc] init];
//所要跳轉(zhuǎn)頁面PowerViewController中有個屬性dictionary1是個NSMutableDictionary類型的容器
[power.dictionary1 setObject:[self.outTxtPass text] forKey:ALONE_SITEPRIZE_PWD];
//使用pushViewController跳轉(zhuǎn)到下一頁面
[self.navigationController pushViewController:power animated:YES];
2朴下、從當前頁面返回到上一頁面并傳值過去:
//此頁面已經(jīng)存在于self.navigationController.viewControllers中,并且是當前頁面的前一頁面
PowerViewController*power= [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2];
//初始化其屬性
power.dictionary = nil;
//傳遞參數(shù)過去
power.dictionary = [NSMutableDictionary dictionaryWithDictionary:self.dictionary1];
//使用popToViewController返回并傳值到上一頁面
[self.navigationControllerpopToViewController:poweranimated:YES];
返回到上一頁后努咐,上一頁面顯示后要接收參數(shù),并刷新殴胧。注意此時應(yīng)該在viewDidAppear中進行判斷并接收傳遞的值:
-(void)viewDidAppear:(BOOL)animated
{
//判斷并接收返回的參數(shù)
}
3渗稍、從當前頁面返回到上一頁面(無需傳值)的方法:
//返回到上一界面
-(IBAction)backOff:(id)sender
{
[self.navigationController popViewControllerAnimated:true];
}
(二)關(guān)于ios中 viewcontroller的跳轉(zhuǎn)問題,其中有一種方式是采用navigationController pushViewController 的方法团滥,比如我從主頁面跳轉(zhuǎn)到了一級頁面竿屹,又從一級頁面跳轉(zhuǎn)到了二級頁面,然后從二級頁面跳轉(zhuǎn)到了三級頁面灸姊,依次類推拱燃。如果一級一級的返回我知道是沒有問題的,調(diào)用navigationControllerpopViewControllerAnimated就行了力惯。但是某些情況下我可能想要馬上回到主頁面碗誉,而不是一級一級的返回(如果有很多層會很累的),那該怎么辦呢父晶?
1.返回根頁面vc用
[self.navigationController popToRootViewController]
2.返回根頁面vc用 :
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
或(通過class定位)
for(UIViewController *controller in self.navigationController.viewControllers) {
if([controller isKindOfClass:[TargetControllerclass]]) {
[self.navigationController popToViewController:controller animated:YES];
}
}