Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

ios - instantiateViewControllerWithIdentifier - Storyboard id set but still not working

I have to created a segue programmatically however when I click on the button the view controller does not change to the next, Storyboard ID is set and still not working. Am I missing any other checks in order to make this work?

Please see code below:

EntryViewController *entryController = [self.storyboard instantiateViewControllerWithIdentifier:@"go"];
[self.navigationController pushViewController:entryController animated:YES];

its driving me mad. Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Inside my viewDidLoad I have placed the button which calls goldStarOpen:

UIButton *btnTwo = [UIButton buttonWithType:UIButtonTypeCustom];
btnTwo.frame = CGRectMake(250, 20, 40, 40);
[btnTwo addTarget:self action:@selector(goldStarOpen) forControlEvents:UIControlEventTouchUpInside];
[btnTwo setImage:[UIImage imageNamed:@"GoldStar.png"] forState:UIControlStateNormal];
[self.view addSubview:btnTwo];

Inside goldStarOpen I have code which is almost identical to yours.

- (void)goldStarOpen
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
                                @"MainStoryboard" bundle:[NSBundle mainBundle]];
    UIViewController *myController = [storyboard instantiateViewControllerWithIdentifier:@"GoldStar"];
    [self presentViewController:myController animated:YES completion:nil];
}

goldStarOpen activates a ViewController in the storyboard.

You may need to set the Storyboard ID of the View Controller you are trying to load. This is located in the inspector, just below where you assign a custom class to your view controller.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...