سؤال

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