Reputation: 641
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
Upvotes: 4
Views: 2156
Reputation: 3404
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];
Upvotes: 9
Reputation: 641
-(IBAction)openModelView:(id)sender
{
ModelViewController *modelView= [self.storyboard instantiateViewControllerWithIdentifier:@"ModelViewController"];
[self.view addSubview:modelView.view];
[self addChildViewController:modelView];
}
Upvotes: 1