views:

181

answers:

1

I have an UITableViewController as the rootViewController for my navigatorController. When I press a table cell I do the following:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath   *)indexPath {
MessageHistory *msg = (MessageHistory *)[[self fetchedResultsController]objectAtIndexPath:indexPath];
ConversationViewController *chatController = [[ConversationViewController alloc]initWithNibName:@"ConversationView" bundle:nil andUser:msg.user];
[self.navigationController pushViewController:chatController animated:YES];
[chatController release];

But when I'm returning from the chatController (using the back button on the navbar) I get “EXC_BAD_ACCESS”

commenting

//[chatController release];

solves the problem. How? I thought when pushing to the navigationController adds a retain count and when pop from it release it?
Also I believe if I'm not including the release after pushing to the navcontroller I'm generating a leak.
Any idea what's happening here?

A: 

I've had this problem a few times, and almost went crazy trying to find the error.

In my case, I had a UIWebView in my second view with the UIViewController set as it's delegate. In my UIViewController dealloc method, I forgot to put webView.delegate = nil.

When the second UIViewController was popped and thus deallocated, the UIWebView was sending a message to it's delegate (the second UIViewController, which didn't exist anymore).

Don't know if this applies to you, but I spend days searching for this error, so perhaps it is of any help.

Rengers
Thanks for sharing although it was not my problem (see my comment to Vladimir's), yours is a scenario I will probably reach on my project too. Nice to keep it in mind
sharkan