문제

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];

다른 팁

-(IBAction)openModelView:(id)sender
{
   ModelViewController *modelView= [self.storyboard instantiateViewControllerWithIdentifier:@"ModelViewController"];

    [self.view addSubview:modelView.view];
    [self addChildViewController:modelView];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top