I have added another view controller to a viewcontroller view ,
addsubview works fine, but the button actions in next view are not working.
crashes with an error [ModelViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0xa81d960
in View1 : Current view controller UsersViewController class
-(IBAction)openModelView:(id)sender
{
ModelViewController *modelView= [self.storyboard instantiateViewControllerWithIdentifier:@"ModelViewController"];
[self.view addSubview:modelView.view];
}
In View 2 ModelViewController class
-(IBAction)dismissModelView:(id)sender
{
NSLog(@"ddddddde");
//[self.view removeFromSuperview];
[self.view removeFromSuperview];
}
It works fine by using presentViewConroller [self presentViewController:modelView animated:NO completion:nil]
*works well*,
but i need to display first view in background with some partial transparent
This is the scope problem ,just add the child controller to the root view controller to avoid the crash.
self.view addSubview:modelView.view];
[self addChildViewController:modelView];
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