UINavigationController
UINavigationController *nav = [[UINavigationController alloc] init];
CTOneViewController *one = [[CTOneViewController alloc] init];
//方法一
[nav pushViewController:one animated:YES];
//方法二
[nav addChildViewController:one];
//方法三
nav.viewControllers = @[one];
//方法四
[nav showViewController:one sender:nil];
//方法一:撤销当前栈顶控制器,返回上一个控制器
[self.navigationController popViewControllerAnimated:YES];
//方法二:popToViewController撤销到指定控制器,只能传递栈中控制器
CTTwoViewController *vc = self.navigationController.viewControllers[1];
[self.navigationController popToViewController:vc animated:YES];
//方法三:直接返回到栈底控制器
UIBarButtonItem *buttonItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:selfaction:@selector(Back:)];
UIBarButtonItem *buttonItem2 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"zhongguo"] style:UIBarButtonItemStyleDone target:self action:@selector(Back:)];
UIBarButtonItem *buttonItem3 = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:selfaction:@selector(Back:)];
self.navigationItem.leftBarButtonItem = buttonItem1;
self.navigationItem.leftBarButtonItems = @[buttonItem1, buttonItem2, buttonItem3];
@property (nonatomic, readonly) NSString *identifier;//唯一标识
@property (nonatomic, readonly) id sourceViewController;//来源控制器
@property (nonatomic, readonly) id destinationViewController;//目标控制器
[self performSegueWithIdentifier:@"login2contacts" sender:nil];
//直接赋值
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
CTContactsTableViewController *contact = segue.destinationViewController;
contact.navigationItem.title = [NSString stringWithFormat:@"%@的通讯录", self.textAccount.text];
}
//在执行跳转前,当前控制器在调用prepareForSegue方法后成为目标控制器的代理
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
CTAddViewController * addViewController = (CTAddViewController *)segue.destinationViewController;
addViewController.delegage = self;
}
//实现目标控制器代理中的方法,可获取数据并触发相应的操作
- (void)addViewControllerBtnSave:(CTAddViewController *)addViewController
{
CTContact *contact = addViewController.contact;
[self.contacts addObject:contact];
如果需要在跳转页面的时候,做一些操作效果,可以自定义导航控制器重写push或者pop方法(重写这个方法,也可以取消一些不想要的效果),或者作为导航控制器的代理,监听跳转方法。
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController*)viewController animated:(BOOL)animated