You create a new view controller:
MainViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainController"];
But you do not save it. Your view hierarchy as soon as you add it to another view.
[self.view addSubview:mvc.view]
So, when the button is pressed, an IBAction
message is sent to you, but your view controller has already been released. To prevent this, save the mvc
variable, for example, somewhere in the property.
@property(nonatomic, strong) MainViewController *controller; self.controller = mvc;
source share