I have this large table which works without errors, even if seems to me too slow compared to more complex cells i've opened from downloaded examples. The problem comes when i click a cell, then came back, in few seconds of scrolling fast the app is crashing at the line: charImage.image = [self imageForIndex:ch.charId];
If i delete it is crashing at the next line: titleLabel.text = ch.title;
Is anybody familiar with this? Thanks.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//NSLog(@"add a new cell at index path %@", indexPath);
// Each subview in the cell will be identified by a unique tag.
static NSUInteger const kTitleLabelTag = 2;
static NSUInteger const kCharImageTag = 3;
static NSString *kCellID = @"CellID";
// Configure the cell
// Declare references to the subviews which will display the char data.
UILabel *titleLabel = nil;
UIImageView *charImage = nil;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
if (cell == nil) {
// No reusable cell was available, so we create a new cell and configure its subviews.
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[cell setBackgroundColor:[UIColor clearColor]];
//
charImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"glyphs/a/1.png"]] autorelease];
charImage.tag = kCharImageTag;
charImage.autoresizingMask = UIViewAutoresizingNone;
[cell.contentView addSubview:charImage];
titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(60, 10, 215, 20)] autorelease];
titleLabel.tag = kTitleLabelTag;
titleLabel.font = [UIFont systemFontOfSize:16];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.adjustsFontSizeToFitWidth = YES;
[cell.contentView addSubview:titleLabel];
} else {
// A reusable cell was available, so we just need to get a reference to the subviews using their tags.
charImage = (UIImageView *)[cell.contentView viewWithTag:kCharImageTag];
titleLabel = (UILabel *)[cell.contentView viewWithTag:kTitleLabelTag];
}
// Get the specific info for this row.
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
Char *ch = (Char *)[charsList objectAtIndex:row+section*26];
// Set the relevant data for each subview in the cell.
// Set the image in the cell
charImage.image = [self imageForIndex:ch.charId];
[charImage sizeToFit];
int centerX = 30;
int centerY = 23;
CGSize size = charImage.frame.size;
charImage.frame = CGRectMake((int)(centerX - size.width / 2),
(int)(centerY - size.height / 2),
size.width, size.height);
titleLabel.text = ch.title;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
InstantInsightAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
Char *ch = (Char *)[charsList objectAtIndex:row+26*section];
SqlQueries *db = [SqlQueries alloc];
NSArray *glyphsList = [db readGlyphsFromDatabaseAtId: ch.charId];
NSArray *charDescription = [db readMoreInfoFromDatabaseAtId: ch.charId];
Char *charDetails = [db readInstructionsAndQuotesFromDatabaseAtId: ch.charId];
[db release];
[ch release];
// Navigation logic -- create and push a new view controller
self.glyphsView = [[GlyphsViewController alloc] initWithStyle:UITableViewStyleGrouped];
self.glyphsView.glyphsList = glyphsList;
self.glyphsView.charDetails = charDetails;
self.glyphsView.charDescription = charDescription;
[delegate.navController pushViewController:self.glyphsView animated:YES];
[self.glyphsView release];
self.glyphsView = nil;
}