5

Currently, when a button is tapped, a UIModalPresentationSheet comes up. I'd like to add a navigation bar at the top of this when it slides up. I've tried a lot of things but nothing seems to work. Here's what i'm currently trying and it returns this error.

    AthleteAdd *addAthlete = [self.storyboard instantiateViewControllerWithIdentifier:@"addAthlete"];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addAthlete];
    //[self.navigationController pushViewController:addAthlete animated:YES];

    addAthlete.delegate = self;
    addAthlete.modalPresentationStyle = UIModalPresentationFormSheet;
  //  UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addAthlete];
    [self presentViewController:navigationController animated:YES completion:nil];

But it pushes it up modally, and without the modalpresentationsheet form. How can I make it so the navigation controller is sized correctly?

3 Answers 3

12

Try to change your code like this :

    AthleteAdd *addAthlete = [self.storyboard instantiateViewControllerWithIdentifier:@"addAthlete"];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addAthlete];

    addAthlete.delegate = self;
    navigationController.modalPresentationStyle = UIModalPresentationFormSheet;


    [self presentViewController:navigationController animated:YES completion:nil];

Because here, you try to present addAthlete from itself. So you get this error.

0
4

You should present navigationController in which you encased your addAthlete.

[self presentViewController:navigationController animated:YES completion:nil];
0

You are presenting from current viewcontroller itself.

Try something like,

[self dismissViewControllerAnimated:YES completion:^{
   [self.parentViewController presentViewController: navigationController animated:YES completion:nil];
}];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.