我们常常有这种需求,有A,B,C三个视图器,依次是从A中跳转到B,从B中跳转到C,那么问题来了,如何从C直接跳转到A呢

首先在A的视图控制器中添加一个方法:
- (IBAction)unwindMethod :(UIStoryboardSegue *)sender{
}
打开故事板,选择C控制器,连接C的button和exit

现在运行程序,从A跳转到B,从B跳转到C,点击C Button看看是不是直接就跳到了A呢

我们还可以这样,在B中添加一短跟A中一样的方法签名的如我随便起个名字叫jumpToB
- (IBAction)jumpToB:(UIStoryboardSegue *)sender{
}
删除刚才C中的连线重新连接到Exit,可以发现多出一个Action Segue

重新运行,可以发现从C跳转到了B,依次类推你可以在storyboard是实现任意展线。
让我们试试一个更强大的功能,如果不同的storyboard会怎么样呢,还能这么跳转吗,答案是肯定的,实验一下,新建一个test2.storyboard,添加一个button D,我们先连一下线试试:

居然还是都检测出来了,我们选择一个试试看看能跳转过去不
完成C控制器中的代码跳转
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"test2" bundle:[NSBundle mainBundle]];
UIViewController *vcd = [storyboard instantiateInitialViewController];
[self.navigationController pushViewController:vcd animated:YES];
运行试试

我和小伙伴都惊呆了,强大的storyboard
源代码地址
网友评论