使用Custom Segue以编程方式导航到另一个ViewController [英] Navigate to another ViewController programmatically using Custom Segue
问题描述
我在情节提要中有两个视图控制器.我确实以编程方式成功地从第一个导航到了第二个:
I have two view controllers in the storyboard. I did successfully navigate from the 1st one to 2nd one programmatically:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
YourViewController *yourViewController = (YourViewController *)[storyboard instantiateViewControllerWithIdentifier:@"yourViewControllerID"];
[self.navigationController pushViewController:yourViewController animated:YES];
我想使用我的 custom
Segue而不是 pushViewController
导航到其他页面,而无需使用界面生成器.
I want to use my custom
Segue to navigate to other page instead of pushViewController
without using interface builder.
这是我的自定义Segue,可以轻松地与界面生成器一起使用:
This is my custom Segue that I could easily use with interface builder:
@interface LeftToRightSegue : UIStoryboardSegue
如何通过编程实现呢?
推荐答案
这是我的操作方法.我创建了我的segue子类,然后从我所在的sourceViewController IE中调用它,初始化我的destinationViewcontroller,然后将它们传递给我的自定义segue类.
Here's how I've done it. I create my segue subclass then call it from my sourceViewController IE the one I'm in, init my destinationViewcontroller then pass them to my custom segue class.
YourViewController *yourViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"YOURStoryboardViewControllerID"];
CustomSegueClass *segue = [[CustomSegueClass alloc] initWithIdentifier:@"ANYid" source:self destination:yourViewController];
[segue perform ];
这篇关于使用Custom Segue以编程方式导航到另一个ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!