Step 1: Set a Storyboard IDIn the Storyboard, select the view controller that you want to instantiate in code. Make sure the yellow circle is highlighted, and click on the Identity Inspector. Set the custom class as well as the field called "Storyboard ID". You can use the class name as the Storyboard ID.
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.
Use
+ (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle *)storyboardBundleOrNil.
So try this
self.storyboard=[UIStoryboard storyboardWithName:@"Your_Story_Board_Name" bundle:[NSBundle mainBundle]];
EntryViewController *entryController = [self.storyboard instantiateViewControllerWithIdentifier:@"go"];
[self.navigationController pushViewController:entryController animated:YES];
try this Storyboard Choose UIViewController-> Xcode->Editor->Emabed In->Navigation Controller
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"YourStoryboard"
bundle: nil];
YourViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier: @"YourViewController"];
[self.navigationController pushViewController:vc animated:YES];
Try this,
UIStoryboard * storyboardobj=[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
EntryViewController *entryController = [storyboardobj instantiateViewControllerWithIdentifier:@"go"];
[self.navigationController pushViewController:entryController animated:YES];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With