I have an array of 5 items that is also used as the content for a tableview. In the nib is a button that changes the content of the array to 5 different items. When I click that button, however, the app crashes with an EXC_BAD_ACCESS. I set a breakpoint on objc_exception _throw and had my suspicions confirmed. The bad method is
- (id)tableView:(NSTableView *)wordsTableView
objectValueForTableColumn:(NSTableColumn *)column
row:(int)rowIndex
{
return [[currentCard words] objectAtIndex:rowIndex];
}
currentCard is an instance of the GameCard class, and its array, words, is the array in question. On first launch, it works fine, but if I try to change it, crash.
----------EDIT----------
In AppController's awakeFromNib: I have this
currentCard = [[GameCard alloc] init];
And in the button's IBAction, I have this:
[currentCard release];
currentCard = [[GameCard alloc] init];
With zombies enabled, when I click the button, I get this from GDB:
2009-06-22 18:55:03.368 25WordsMax[19761:813] *** -[CFArray objectAtIndex:]: message sent to deallocated instance 0x14ba00
referring to the data source method. I've been trying to track down the memory bug for hours, but am missing it.
I got so frustrated I commented out every retain & release (no autoreleases) in the code and still get 2009-06-22 19:41:58.564 25WordsMax[21765:813] *** -[CFArray objectAtIndex:]: message sent to deallocated instance 0x14c330 when I hit the button.
And what is calling the datasource method? I'm not calling reloadData. If in my datasource method, I return @"A Word" for each row, everything runs fine. In GDB, I can even see my NSLogs printing the contents of the new array, all without a hitch. It's only when the datasource method as seen in the question gets called that any problems happen.