I'm getting a consistent crash when I create a simple app that uses a navigation controller.
Basically choosing an item in the first table successfully creates & pushes the sub viewcontroller, and the back button works just fine. But when I try to choose the item again I get a strange crash in GDB. I get no errors, simply the debugger spits out some information and the application hangs.
Here's where I push the view controller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *viewController;
NSString *selection = [items objectAtIndex:indexPath.row];
if([selection isEqualToString:@"Artists"]) {
NSLog(@"Selected artists");
if(artistsViewController == nil) {
NSLog(@"creating ArtistsViewController");
artistsViewController = [[ArtistsViewController alloc] init];
}
viewController = artistsViewController;
}
if(viewController != nil) {
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
}
}
I have no need of keeping the view controller around, so I simply create it every time and release it when I'm finished.
Here's the unhelpful Console log. Notice how it says "Selected artists" and then "creating ArtistsViewController" the first time, then the 2nd time it says "Selected artists" and then it dies:
[Session started at 2009-06-08 18:00:16 -0500.]
2009-06-08 18:00:18.856 Pocket Tabs[96726:20b] View did load
2009-06-08 18:00:18.862 Pocket Tabs[96726:20b] loading data for tableview
2009-06-08 18:00:20.265 Pocket Tabs[96726:20b] Selected artists
2009-06-08 18:00:20.265 Pocket Tabs[96726:20b] creating ArtistsViewController
[Session started at 2009-06-08 18:00:22 -0500.]
2009-06-08 18:00:22.061 Pocket Tabs[96726:20b] Selected artists
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".warning: Unable to read symbols for "/System/Library/Frameworks/UIKit.framework/UIKit" (file not found).
warning: Unable to read symbols from "UIKit" (not yet mapped into memory).
warning: Unable to read symbols for "/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics" (file not found).
warning: Unable to read symbols from "CoreGraphics" (not yet mapped into memory).
Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/ben/Library/Application Support/iPhone Simulator/User/Applications/F063AD87-BEFE-4CB9-AE26-E7149C8D7D4C/Pocket Tabs.app/Pocket Tabs', process 96726.
(gdb)
Any ideas? I'm stumped.
EDIT: I figured it out. Looks like I was in the middle of assigning this to an instance variable to avoid re-allocation of the sub view and I must have switched gears and forgot about it. Eliminating the instance variable artistsController solved it.