ios app is crashing
I'm having a problem with my app crashing. The main root controller is a tab controller. inside the tab controller i have 4 buttons that have a nav controllers hooked up to them. inside the nav controller, i have a table controller with a few cells. when you click a cell, it takes you to a view controller. now when i click on the cell and it takes me to the view controller. when i click on the back arrow on the nav controller, it takes me back to the table view, which is great, but when i click on a new cell, the app crashes. everytime i click a cell, go back, and click another cell, the app crashes. what am i doing wrong? i think i too care of all my releases. not sure though.
Theres an error I get when I run the program. It reads:
Book Nav Controller (Me开发者_JAVA技巧dical How To's) has it 'NIB Name" property set to 'BookTableViewController.nib', but this view controller is not intended to have its view set in this manner.
I'm also getting setText is deprecated on this code:
cell.text = [breakdownArray objectAtIndex:row];
What do I change it to?
Also My didSelectRowAtIndexPath code is:
NSInteger row = [indexPath row];
if (self.bookDetailViewController == nil); {
BookDetailViewController *aBookDetail = [[BookDetailViewController alloc] initWithNibName:@"BookDetailView" bundle:nil];
self.bookDetailViewController = aBookDetail;
[aBookDetail release];
}
bookDetailViewController.title = [NSString stringWithFormat:@"%Breakdown" , [breakdownArray objectAtIndex:row]];
Surviving2012AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.breakdownNavController pushViewController:bookDetailViewController animated:YES];
[delegate release];
}
cell.text = [breakdownArray objectAtIndex:row];
Should be:
cell.textLabel.text = [breakdownArray objectAtIndex:row];
bookDetailViewController.title = [NSString stringWithFormat:@"%Breakdown" , [breakdownArray objectAtIndex:row]];
Should be:
bookDetailViewController.title = [NSString stringWithFormat:@"%@", [breakdownArray objectAtIndex:row]];
If you're calling this from one of the viewControllers in the tabBarController, then this:
Surviving2012AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.breakdownNavController pushViewController:bookDetailViewController animated:YES];
[delegate release];
Should be:
[self.navigationController pushViewController:bookDetailViewController animated:YES];
And if it's still crashing after that, then you'll need to post how you're defining:
bookDetailViewController in your .h file, and the contents of your viewWillAppear and viewDidLoad methods.
As for your deprecated method:
change it to :
cell.textlabe.text = [breakdownArray objectAtIndex:row];
And I dont get the hang of this:
Surviving2012AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.breakdownNavController pushViewController:bookDetailViewController animated:YES];
[delegate release];
You said that you have a navigationController in every tab? Then why don't you use it?
[self.navigationController pushViewController:bookDetailViewController
animated:YES];
Apple's iOS Reference Library -- available right there in Xcode under Help->Developer Documentation -- very clearly lays out what to replace the deprecated .text property with: .textLabel and .detailTextLabel.
definitely don't call release on the delegate. you only call release on an object when you have used a method on it which contains: alloc/init, copy, new or retain. otherwise you are likely releasing an autoreleased instance, which will cause it to crash.
fix this, if it still happens, post your results, and we will have another look.
精彩评论