Perform Segue from Xib programmatically

ε祈祈猫儿з 提交于 2019-12-07 18:50:28

问题


I've search a lot but I can't do yet.

I've my .xib UI with some buttons, separated from main storyboard.

I need to perform an action when I press one of this button and show another view.

How can I do this directly from code such ad inside an IBAction?


回答1:


You can't perform segues from XIB to Storybaord,
Instead of it you need
1) Get Storyboard's instance.
2) Instantiate a ViewController that is inside the Storyboard (By using Storyboard ID).
3) Push that ViewController to to your navigation stack.

Here is sample code

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

@"MainStoryboard" - is the file name of storybaord (note. it's without .storyboard extension)
@"yourVcIdentifier" - is ViewController's Storybaord ID.

To give a Storybaord ID to some ViewController, open the storybaord, click on the ViewController and specify the "Storyboard ID" field.



来源:https://stackoverflow.com/questions/26712758/perform-segue-from-xib-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!