10M2003+7D11: setViewControllers:animated: keeps root leftBarButtonItem

Number:rdar://7470644 Date Originated:12/14/2009
Status: Resolved:
Product:iPhone SDK Product Version:10M2003+7D11
Classification:Serious Bug Reproducible:Always
When your navigation stack's root view controller has a leftBarButtonItem, calling setViewControllers:animated:YES with one or more additional VCs keeps the root leftBarButtonItem on screen.  The proper top item's back button is also visible, but the root VC's button is highlighted and its action selector is called when tapping.

See attached project and screenshot.  This problem does not occur if you pass animated:NO.  I've tried a few workarounds, including setting the leftBarButtonItem to nil before proceeding and/or deferring the call to setViewControllers via performSelector:withObject:afterDelay, but had no luck.



Below is a solution to the issue (which should still work, even after apple fixes this).

-(void) pushMethod


UIViewController *controller = [[UIViewController alloc] initWithNibName:@"xxxView" bundle:nil];

[controller autorelease];

[self.navigationController pushViewController:controller animated:YES];

[self performSelector:@selector(updateMyControllers) withObject:nil afterDelay:0.5];

// note that a 0.5 delay works well, but a 0.1 delay does not (leftBarButton still overlays)


(void) updateMyControllers


NSArray *controllers = [NSArray arrayWithObjects: [self.navigationController.viewControllers objectAtIndex:0] , [self.navigationController.viewControllers objectAtIndex:[self.navigationController.viewControllers count]-1] , nil];

[self.navigationController setViewControllers:controllers animated:NO];

// don't forget to add your desired controllers between indexes 0 and count-1


Hope this helps.

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!