UINavagationController页面跳转

时间:2022-12-19 23:38:01

1.在AppDelegate中设置第一个加载的页面,根VIEW

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

FirstViewController *firstController = [[FirstViewController alloc] init];

self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:firstController];

self.window.backgroundColor = [UIColor whiteColor];

[self.window makeKeyAndVisible];

return YES;

}

2.页面跳转

SecondViewController *secondController = [[SecondViewController alloc]init];

[self.navigationController pushViewController:secondController animated:YES];

3.页面返回

-(void)backToFirstClick

{

UINavigationController *topNavagation  = self.navigationController.topViewController;

if([topNavagation isKindOfClass:[SecondViewController class]])

{

UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"" message:@"确定要返回第一个页面吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

[alertView show];

}

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

if(buttonIndex == 1)

{

[self.navigationController popViewControllerAnimated:YES];

}

}