For my UITableView I use an array as a datasource. Everything works fine so far. However, I have the weird issue, that when I use the search field and enter a few characters, which I afterwards delete again, the underlying array is suddenly empty. Here the code snippets, which might be relevant to understand my issue:
Declaration in my .h
@interface dictionaryViewController : UIViewController <UITableViewDelegate>{
...
...
NSMutableArray *cardArray;
}
...
@property (retain) NSMutableArray *cardArray;
...
Usage in my .m code:
@synthesize cardArray;
...
- (void)viewDidLoad {
[super viewDidLoad];
self.cardArray = [[NSMutableArray alloc] initWithObjects:nil];
...
}
I populate the array with data from my SQL DB:
[self.cardArray addObject:[NSString stringWithFormat:@"%@ - %@", aQuestion, anAnswer]];
And within the code read the content of the array like in the cellForRow method:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
thisCardIndex = [self.cardArray indexOfObject:cellValue];
...
}
At the end I release it, like this (I actually had some other issues with the release command, why I used the removeObjects instead):
[self.cardArray removeAllObjects];
self.cardArray=nil;
In the log I do not see an error. The debugger shows, however, that the code crashes with a SIGABRT and when setting breakpoints I see, that the cause is the empty cardArray.
Thanks for the support in advance.
ok, finally found the culprit, it was the [myArray release] (see commented line below). I have no clue, WHY though. This is a local array, which I define locally and also should be able to release immediatly again. And the interesting part is, that this code works as long as the search is narrowing. It only crashes, when the search field is empty again. VERY confusing, but maybe someone has an explanation?? Anyway, finally got it and it ru as expected.
// [myArray release];
}