@在之前的几篇文章,已经介绍了storyboard页面之间的跳转和传值,对于那几种传值方法,其实与纯代码构建的页面传值是一个道理,都是可以用属性,代理,通知,block,单例等方法传值(具体可见iOS高级),storyboard只是帮我们简化了构建view的代码,整体的原理还是一样的,主要是获得跳转的那个ViewController对象即可,下面,我就给出种方式的关键代码:
2种的ID不一样,一种是中间连线那个圈圈里面的Identifier,一种是跳转页面的Storyboard ID
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// self.selectedIndex = indexPath.row;
// [self performSegueWithIdentifier:@"classDetail" sender:nil];
/*---------------------------------第二种传值-----------------------------------------*/
LOClassDetailTableViewController *classDeatailVC = [self.storyboard instantiateViewControllerWithIdentifier:@"LOClassDetailTableViewController"];
classDeatailVC.loClass = self.loClasses[indexPath.row];
[self.navigationController pushViewController:classDeatailVC animated:YES];
/*---------------------------------第一种传值(1)-----------------------------------------*/
self.selectedIndex = indexPath.row;
[self performSegueWithIdentifier:@"classDetail" sender:self];
}
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
/*---------------------------------第一种传值(2)-----------------------------------------*/
LOClassDetailTableViewController *classDetailVC = segue.destinationViewController;
NSLog(@"---%ld",self.selectedIndex);
classDetailVC.loClass = self.loClasses[self.selectedIndex];
}
一个没有导航栏(有的直接push想要那个viewController就行,会统一自带)的viewController模态推出一个在storyboard中拖入的UINavigationController,如何找到导航控制器下的viewController,给予UINavigationController的storyboardID就行
UINavigationController *deatilNC = [self.storyboard instantiateViewControllerWithIdentifier:@"MDCDeatilBusinessNiewController"];
// 导航控制器有属性viewControllers,就跟标签控制器一样
MDCDeatilBusinessViewController *deatilVC = deatilNC.viewControllers[0];
[self presentViewController:deatilNC animated:YES completion:nil];
多个storyboard之间沟通只能手写
UIStoryboard *secondStoryboard = [UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:nil];
UIViewController *firstVC = [secondStoryboard instantiateViewControllerWithIdentifier:@"firstVC"];
[self.navigationController pushViewController:firstVC animated:YES];
@QQ的登录,注册,找回密码用一个storyboard;登录成功后的主界面的链接用一个storyboard
// 多个storyboard的衔接
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isAuthenticated"] == NO) {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *viewController = [mainStoryboard instantiateInitialViewController];
[UIApplication sharedApplication].keyWindow.rootViewController = viewController;
}