Pregunta

I am troubling with an issue and I cannot be able to solve it!

The scenario is the next one: - I have 4 view controller (main view controller is an UITableView, settingsVC, messsageDetailController and moreInfoVC). - I also have a listener (NSObject) which is listening a port for different events to receive.

Then, functionality is the next one: - I launch the listener to receive those events. When the listener receives a new event, this listener communicates to the mainViewController, and from this mainVC I create a new instance of messageDetailController. *Im using the below code (mainVC):

[self performSegueWithIdentifier:@"MessageDetail" sender:self];

I got all this functionality, but my problem starts when my listener receives more than one event and then, consequently, I create more than one messageDetailController reference. That problem affects directly to my NavigationController which is popping me out next messages: - nested push animation can result in corrupted navigation bar - Unbalanced calls to begin/end appearance transitions for . - Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

I hope that I explained myself properly and anyone could help me.

¿Fue útil?

Solución 2

Solution:

NSMutableArray *array = [NSMutableArray arrayWithArray::self.navigationController.viewControllers];

for(NSInteger i = ([array count] - 1); i > 0; i--)
    if(i != 0)
        [array removeObjectAtIndex:i];

self.navigationController.viewControllers = array;

[self performSegueWithIdentifier:@"MessageDetail" sender:[settingsReference actualView]];

Otros consejos

You probably don't want to use a segue to do what you're trying to do here, because a segue always creates a new view controller. It would be better to push to the messageDetailController in code, so that you can put an if clause in there that only creates and pushes the controller if one doesn't exist. When a second event comes in, you want only to change the value of what you're displaying. The code could be something like this (in main view controller, I guess, if that's what gets the info from the listener).

if (! messageDetailController) {
    MessageDetailController *messageDetailController = self.storyboard instantiateViewControllerWithIdentifier:@"MessageController"];
    messageDetailController.detailItem = infoFromListener;
    [self.navigationController pushViewController:messageDetailController animated:YES];
}else{
    messageDetailController.detailItem = infoFromListener;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top