标签:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Test" bundle:nil];
2.接着初始化storyboard中的控制器
MJViewController *mj = [storyboard instantiateInitialViewController];
MJViewController *mj = [storyboard instantiateViewControllerWithIdentifier:@”mj"];
完整方式:
UIStoryboard *story=[UIStoryboard storyboardWithName:@"NJWisdomCard" bundle:nil]; NJWisdomCardDetailViewController *wisdom=[story instantiateViewControllerWithIdentifier:@"NJWisdomCardDetailViewController"]; wisdom.bindaliascode=cardId; wisdom.hidesBottomBarWhenPushed=YES; [self.navigationController pushViewController:wisdom animated:YES];
每一个Segue对象,都有3个属性
@property (nonatomic, readonly) NSString *identifier;
@property (nonatomic, readonly) id sourceViewController;
@property (nonatomic, readonly) id destinationViewController;
[self performSegueWithIdentifier:@"login2contacts" sender:nil];
点击登陆,判断后跳转(手动型)
/** * 登录 */ - (IBAction)login { if (![self.accountField.text isEqualToString:@"mj"]) { // 帐号不存在 [MBProgressHUD showError:@"帐号不存在"]; return; } if (![self.pwdField.text isEqualToString:@"123"]) { // 密码错误 [MBProgressHUD showError:@"密码错误"]; return; } // 显示一个蒙版(遮盖) [MBProgressHUD showMessage:@"哥正在帮你登录中...."]; // 发送网络请求 // 模拟(1秒后执行跳转) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // 移除遮盖 [MBProgressHUD hideHUD]; // 跳转 -- 执行login2contacts这个segue [self performSegueWithIdentifier:@"login2contacts" sender:nil]; }); } /** * 执行segue后,跳转之前会调用这个方法 * 一般在这里给下一个控制器传递数据 */ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // 1.取得目标控制器(联系人列表控制器) UIViewController *contactVc = segue.destinationViewController; // 2.设置标题 contactVc.title = [NSString stringWithFormat:@"%@的联系人列表", self.accountField.text]; } @end
多个控制器跳转(自动)
/** * 执行跳转之前会调用 * 在这个方法中,目标控制器的view还没有被创建 */ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { id vc = segue.destinationViewController; if ([vc isKindOfClass:[MJAddViewController class]]) { // 如果是跳转到添加联系人的控制器 // 设置下一个控制器(添加联系人的控制器)的代理 MJAddViewController *addVc = vc; addVc.delegate = self; } else if ([vc isKindOfClass:[MJEditViewController class]]) { // 如果是跳转到查看(编辑)联系人的控制器 MJEditViewController *editVc = vc; // 取得选中的那行 NSIndexPath *path = [self.tableView indexPathForSelectedRow]; editVc.contact = self.contacts[path.row]; editVc.delegate = self; } }
标签:
原文地址:http://www.cnblogs.com/jys509/p/4825581.html