两个方法都是用ViewController是建立在UINavigationController之上的 例如: TestViewController *testViewController = [[TestViewController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: testViewController]; [self.window addSubview:nav.view];
UINavigationController是导航控制器,如果pushViewController的话,会跳转到下一个ViewController,点返回按钮会回到现在这个ViewController,推出试图push,下一页面会自动添加返回按钮 例如: UserPushViewController *pViewController = [[UserPushViewController alloc] init]; [self.navigationController pushViewController:pViewController animated:YES];
用UINavigationController的时候用pushViewController:animated,其他时候用presentModalViewController:animated
上推一个试图,下一页没有返回按钮,需要自己添加
NewDataViewController *baNewViewController = [[NewDataViewController alloc] init]; UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:baNewViewController]; [self.navigationController presentModalViewController:baNavigation animated:YES]; [baNewViewController release]; [baNavigation release];
下一试图添加返回按钮 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回"style:UIBarButtonItemStyleDone target:self action:@selector(returnView)];
返回方法 - (void)returnView { [self.parentViewController dismissModalViewControllerAnimated:YES]; }
|