iPhone: Bugged UINavigationController? View doesn’t Scroll.
Developing a networked iPhone application, I had two views that were very similar – so similar in fact that they were copies of one-another with “Sending” renamed to “Receiving”. The idea was to get them both working with different XIB files, and then modify them.
The code to load the sending view (from the main app delegate) was:
- (IBAction)sendContact:(id)sender
{
DataController* dc = [DataController sharedInstance];
dc.contactRecord = (NSMutableDictionary*) [self.userDefaults dictionaryForKey:@"currentUser"];
SendingViewController *sendingViewController = [[SendingViewController alloc] initWithNibName:@"ReceiverView" bundle:nil];
[self setBackButtonText:@"Back"];
[self.navigationController pushViewController:sendingViewController animated:YES];
[sendingViewController release];
}
The code for the receiving view was:
- (IBAction)receiveContact:(id)sender
{
ReceivingViewController *receiverViewController = [[ReceivingViewController alloc] initWithNibName:@"ReceivingView" bundle:nil];
[self setBackButtonText:@"Back"];
[self.navigationController pushViewController:receiverViewController animated:YES];
[receiverViewController release];
}
On load, I could _swear_ that nothing happend with the DataController’s contact record. But something screwy was going on. When I hit “send” first (on app launch), hitting “receive” worked fine (you could navigate back with no worries at all). However, when you hit “receive” first, going back only got the navigation bar to change, while the receive view was still visible.
It took ages, but setting contactRecord in the DataController shared instance fixed the problem.
The thing is, the view loaded just fine, no worries at all. No errors or warnings occured… and I wasn’t using contactRecord for anything on the view. So why did it behave like it encountered an error? I searched the code, and I was setting a label (which didn’t even exist on-screen anymore, it was an unused IBOutlet UILabel) to something contained in the DataController. Why it didn’t error properly, and why that stopped the view from unloading properly is completely beyond me… The NavigationBar operates (somewhat) in isolation from the views inside it, so if a view gets stuck (but not the Nav control) you can find yourself in a very weird situation.
So, my advice to you is:
- It ain’t the same until it’s _exactly_ the same.
- Just because it doesn’t error, doesn’t mean it hasn’t produced an error.
- If you can at all avoid it, don’t copy paste entire files. Best to start empty and include the stuff you need instead.

Leave a Reply