Dinesh Raja
Dinesh Raja

Reputation: 8501

How to present modalViewController inside the masterViewController?

I am doing an iPad app with UISplitViewController. I want to open a modalViewController in the masterViewController itself. When I load my view controller modally, it takes a whole screen to present it.

Here it is my code, which is in my masterViewController.m to present the new viewController modally

- (void)addNewContactButtonPressed:(id)sender {
    AddOrEditContact *addContact = [self.storyboard instantiateViewControllerWithIdentifier:@"AddOrEditContact"];
    addContact.screenMode = addMode;
    UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:addContact];
    [self.navigationController presentViewController:navigationController animated:YES completion:nil];
}

I want to load a new viewController modally inside the masterViewController. Any help would be appreciated.

Upvotes: 0

Views: 168

Answers (1)

Manu
Manu

Reputation: 788

You can't present a modal viewController over the masterViewController only, but you can add a childView controller to the masterViewController nd perform your own animation to present it

- (void)addiewControllerToHierarchy:(UIViewController *)viewController
{
    [self addChildViewController:viewController];

    [self.view addSubview:frontViewController.view];

    if ([viewController respondsToSelector:@selector(didMoveToParentViewController:)])
    {
        [viewController didMoveToParentViewController:self];
    }
}

and to remove

- (void)_removeViewControllerFromHierarchy:(UIViewController *)viewController
{
    [viewController.view removeFromSuperview];

    if ([viewController respondsToSelector:@selector(removeFromParentViewController)])
    {
        [viewController removeFromParentViewController];        
    }
}

this example doesn't have animation and probably you need to adjust the frame of the view etc... but I hope could help you

Upvotes: 1

Related Questions