我在我的项目中使用 ARC,当我在设备中运行应用程序时它崩溃了,所以我检查了 command+shift+B,它显示了以下泄漏......下面是我使用过的代码,
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ColourSelectTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
//CGRect frame = CGRectMake(15.0, 5.0, 25.0, cell.frame.size.height-10.0);
selectedLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 5.0, 25.0, cell.frame.size.height-10.0)];
selectedLabel.tag = kSelectedLabelTag;
selectedLabel.font = [UIFont systemFontOfSize:24.0];
selectedLabel.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.0]; // transparent
[cell.contentView addSubview:selectedLabel];
UIImageView *AtoZimage = [[UIImageView alloc] initWithFrame:CGRectMake(70, 10,60, 40)];
UIImage *atozImage = [UIImage imageNamed:[bgArray objectAtIndex:indexPath.row]];
AtoZimage.image = atozImage;
[cell addSubview:AtoZimage];
UILabel *lblTemp1 = [[UILabel alloc]initWithFrame:CGRectMake(150, 10, 190, 40)];
lblTemp1.backgroundColor=[UIColor clearColor];
lblTemp1.tag=kSelectedLabelTag;
lblTemp1.text = [bgNameArray objectAtIndex:indexPath.row];
[lblTemp1 setNumberOfLines:10];
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
[lblTemp1 setFont:[UIFont boldSystemFontOfSize:16]];
[cell addSubview:lblTemp1];
}
// Configure the cell...
UIColor *cellColour = [self.bgArray objectAtIndex:indexPath.row];
CMColourBlockView *colourView = (CMColourBlockView *)[cell viewWithTag:kcolourViewTag];
colourView.colour = cellColour;
selectedLabel = (UILabel *)[cell viewWithTag:kSelectedLabelTag];
if ([self.selectedBg isEqual:cellColour]) {
selectedLabel.text = @"✔";
}
else {
selectedLabel.text = @"";
}
return cell;
}
显示内存泄漏如图