Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton not Working when the UIview is presented by addsubView

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

like image 749
user2732294 Avatar asked Dec 25 '22 21:12

user2732294


1 Answers

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];
like image 80
Arun Avatar answered Mar 30 '23 00:03

Arun