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.

Sign up to request clarification or add additional context in comments.

Comments

4

You should present navigationController in which you encased your addAthlete.

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

Comments

0

You are presenting from current viewcontroller itself.

Try something like,

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.