Search code examples
iosobjective-cuiviewcontrollerpresentviewcontroller

Present a view controller from a container view


I had built a UIViewController with a container a view that embeds another UIViewController(I will call it subViewController). I want the subViewController to present anther instance of it self within its container view canvas (not for all screen).

I tried this using prepareForSegue method with this method

-(void)showFurtherReadingDetails
{
    [self performSegueWithIdentifier:@"ShowArticleDetails" sender:self];
}

Note : the showFurtherReadingDetails method is a delegate method for subVC over, initialized in the supperVC . but I faced this issue:

'NSInternalInconsistencyException', reason: 'There are unexpected subviews in the container view. Perhaps the embed segue has already fired once or a subview was added programmatically?'.

Please see The attached image enter image description here


Solution

  • If your UIViewController is not embedded with UINavigationController then you can not perform Push.

    What you have to do is, embed-in navigation controller with your subVC and then push new view-controller from subVC and it will be in container view and will not take the full screen.

    For your convenience, I attached the screenshot of the storyboard so you can get the better understanding. Hope it will help.

    enter image description here