views:

30

answers:

1

I have a very strange problem with UINavigationController on the iphone and I am banging my head against the wall on this.

Gist of it is I am executing a call to a server and when that call fails I swap out the current view with a view containing an error message. The code in question is called on the main thread by using performSelectorOnMainThread

What happens in practice is that on the device it shows a blank white screen about half the time. On the simulator it presents a blank screen every time leading me to think this is perhaps some kind of timing problem that is more prominent due to better processing speeds in a simulator. This works perfectly if I call the same function by clicking a button in the ui to display the page so I don't think its a problem with the code itself.

I have verified that the controller I am adding is in the navigation stack. Verified it is being called on the main thread, it is visible, the frame size and location are correct. I have tried explicitly setting the view to be visible, moved it to the front in its parent view and called setNeedsDisplay and even manually called drawRect. None of this works.

Any thoughts on what could be going on here? I am assuming it has something to do with the run loop but I can't figure it out. Help would be much appreciated. The relatively simple code in question is below

 UINavigationController* navController = self.navigationController; 

 int count = [navController.viewControllers count];

 NSMutableArray* controllers = [[NSMutableArray alloc] initWithCapacity:count];

 for (int i=0; i<count; i++) {
  if (self == [self.navigationController.viewControllers objectAtIndex:i]) {
   [controllers addObject:newController];
  }
  else {
   [controllers addObject:[self.navigationController.viewControllers objectAtIndex:i]];
  }

 }
 [self.navigationController setViewControllers:controllers animated:YES];
 [controllers release]; 
A: 

I really don't understand what you're doing there. Something like this won't work?

- (void)displayMyErrorVC {
    MyErrorVC *errorVC = [[[MyErrorVC alloc] init] autorelease];          
    [self.navigationController pushViewController:errorVC animated:YES];
}

And then in your other thread, if you have an error:

[self performSelectorOnMainThread:@selector(displayMyErrorVC) withObject:nil waitUntilDone:NO];
Stelian Iancu
I have tried what you suggested as well with the same result. As I mentioned it works fine from the UI but either of our cases fail from the callback which makes no sense because the push is happening on the main thread. One other note. It does seem to be a much less prevalant problem if I set Animated to NO. I really believe it has to be some kind of timing issue on the rendering. For example if I push 2 controllers rather than 1 than they show up. This is just exceedingly strange. Appreciate any additional thoughts if you have some
Brett Rosen