我在我的项目中使用ARC,当我在设备中运行应用程序时它崩溃所以我检查了命令+ 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;
}
显示内存泄漏,如图所示
答案 0 :(得分:0)
CGRectMake与泄漏无关;泄漏将来自分配两个UILabel和UIImageView。基于我所看到的,ARC没有为您的项目启用,因为ARC将负责在此处释放您分配的对象。
检查ARC是否已启用:
Yes