Question

I am showing up programmatically a modal view controller when the user presses a button on the main view controller. The problem I have is that the modal view is displayed without the navigation bar.

How could I make the bar appear? Please find my code and let me know what is missing or wrong:

-(void)appInfoButtonPressed:(id)sender {
infoViewController *iVC=[[infoViewController alloc] init];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:iVC animated:YES completion:nil];
UINavigationController *navBar = [[UINavigationController alloc] initWithRootViewController:iVC];
[self presentViewController:navBar animated:YES completion:nil];

}

Also in an attempt the dismiss the modal view I have the intention to use the line below:

[self dismissViewControllerAnimated:YES completion:nil];

Should I include this line in a method of the main view controller or in a method of the modal view controller itself?

Was it helpful?

Solution

Delete [self presentViewController:iVC animated:YES completion:nil]; Only to present the UINavigationController.

By the way: It isn't suitable to name a UINavigationController with "navBar".

-(void)appInfoButtonPressed:(id)sender {
    infoViewController *iVC=[[infoViewController alloc] init];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:iVC];
    [self presentViewController:navController animated:YES completion:nil];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top