First of all: I have been doing research and this is a problem many, many developers have, but unfortunately I haven't gotten a solution out of it yet.
Situation: My view is a UITabBar with a UINavigationController and a UITableView. When I scroll the table, it crashes. The error I'm getting is index 9 beyond bounds of empty array, and the ninth table entry happens to be the first one that's not (completely) visible. Anyway, a code snippet says more than a thousand words:
I know it most likely has something to do with memory management, but I can't find it. I've tried retaining sortedBuildingNames because that seemed to be the solution for other people. Not in my case, though...
For some reason sortedBuildingNames becomes empty after the first eight rows are being displayed, but the array should be rebuilt for every cell (which is probably not very efficient?), so I don't understand how it could ever be empty.
Any experts who can shine a light on this?
Situation: My view is a UITabBar with a UINavigationController and a UITableView. When I scroll the table, it crashes. The error I'm getting is index 9 beyond bounds of empty array, and the ninth table entry happens to be the first one that's not (completely) visible. Anyway, a code snippet says more than a thousand words:
Code:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSArray *buildingNames = [self.buildings allKeys];
NSArray *sortedBuildingNames = [buildingNames sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
cell.textLabel.text = [sortedBuildingNames objectAtIndex:indexPath.row];
return cell;
}
I know it most likely has something to do with memory management, but I can't find it. I've tried retaining sortedBuildingNames because that seemed to be the solution for other people. Not in my case, though...
For some reason sortedBuildingNames becomes empty after the first eight rows are being displayed, but the array should be rebuilt for every cell (which is probably not very efficient?), so I don't understand how it could ever be empty.
Any experts who can shine a light on this?