The application tried to introduce a modally active controller: uinavigationcontroller

I have a problem when the error only occurs periodically. In fact, this seems almost random. Here, what happens, I run the modal view controller with the following code:

- (void)createMessageClicked
{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Channel" bundle:nil];
    UINavigationController *nav = [sb instantiateViewControllerWithIdentifier:@"HIComposeMessageNavController"];
    HIComposeMessageViewController *vc = [[nav viewControllers]objectAtIndex:0];

    vc.channel = [self.channels objectAtIndex:0];
    [self.navigationController presentViewController:nav animated:YES completion:nil];
}

In most cases, this works great. However, from time to time, the application crashes and causes an error "Application tried to present modally an active controller <UINavigationController>. Any ideas what I'm doing wrong here?

+3
source share
2 answers

Try creating an instance of the controller built into your storyboard navigation controller, then create a new instance of the universal navigation controller:

HICompseController *controller = [sb instantiateViewController: 
                                  HIComposeMessageViewController];
UINavigationController *nav = [[UINavigationController alloc]
                               initWithRootViewController:controller];
[self presentViewController:nav animated:YES completion:nil];
+6
source

ivar UINavigationController, , , .

, , , , , , , . , , , .

ivar .

+1

All Articles