以编程方式从Xib执行Segue

我经常搜索,但我还不能做。

我的.xib UI带有一些按钮,与主故事板分开。

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

如何直接从IBAction中的代码广告中执行此操作?

你不能执行从XIB到Storybaord的segue,
而不是你需要的
1)获取Storyboard的实例。
2)实例化Storyboard内的ViewController(通过使用Storyboard ID)。
3)将ViewController推送到导航堆栈。

这是示例代码

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

@“MainStoryboard” – 是storybaord的文件名(注意。它没有.storyboard扩展名)
@“yourVcIdentifier” – 是ViewController的Storybaord ID。

要将Storybaord ID提供给某个ViewController,请打开storybaord,单击ViewController并指定“Storyboard ID”字段。 在此处输入图像描述