How to call a View Controller programmatically?

前端 未结 8 2288
孤街浪徒
孤街浪徒 2020-12-02 07:04

I have looked at all the tutorials I can find on this one, and I still don\'t have the answer. I need to call another view from the code. I am using UIStoryboards

8条回答
  •  心在旅途
    2020-12-02 07:20

    You need to instantiate the view controller from the storyboard and then show it:

    ViewControllerInfo* infoController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerInfo"];
    [self.navigationController pushViewController:infoController animated:YES];
    

    This example assumes that you have a navigation controller in order to return to the previous view. You can of course also use presentViewController:animated:completion:. The main point is to have your storyboard instantiate your target view controller using the target view controller's ID.

提交回复
热议问题