Perform Segue Programmatically Without Button Connection?

我的梦境 提交于 2019-12-20 10:23:32

问题


I have two view controllers in my storyboard and I need to push from view 1 to view 2.

I need to do this without connecting a segue directly from a button in my storyboard, I need to do it programatically.

How can I?

Thanks.


回答1:


When you click the button call:

[self performSegueWithIdentifier:@"SegueIdentifier" sender:self];

You will need to create the segue in the storyboard but you can do it from view controller to view controller instead of button to viewcontroller.




回答2:


If you want to perform an action without click (or while loading the viewController itself), do this code in either

- (void)viewDidLoad {
[super viewDidLoad];
[self performSegueWithIdentifier:@"NameOfYourSequeIdentifier" sender:self];
 }

or

-(void)viewDidAppear:(BOOL)animated {
[self performSegueWithIdentifier:@"NameOfYourSequeIdentifier" sender:self];
}



回答3:


Completely w/o segues

[self.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerIDinStoryBoard"] animated:YES];


来源:https://stackoverflow.com/questions/11654003/perform-segue-programmatically-without-button-connection

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