2014-11-03 82 views
2

我已经搜索了很多,但我还做不到。以编程方式从Xib执行Segue

我有我的.xib用户界面与一些按钮,从主故事板分离。

当我按下此按钮之一并显示另一个视图时,我需要执行一个操作。

如何直接从IBAction内的代码这样的广告做到这一点?

回答

5

不能从XIB执行塞格斯到Storybaord,
代替它,你需要
1)获取故事板的实例。
2)实例化Storyboard中的ViewController(通过使用Storyboard ID)。
3)将该ViewController推送到您的导航堆栈。

下面是示例代码

UIViewController *vc = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"yourVcIdentifier"]; 
[self.navigationController pushViewController:vc animated:YES]; 

@ “MainStoryboard” - (注这是不.storyboard扩展名)是storybaord的文件名
@ “yourVcIdentifier” - 是的ViewController的Storybaord ID。

若要给某个ViewController提供Storybaord ID,请打开storybaord,单击ViewController并指定“Storyboard ID”字段。 enter image description here