0

我在我的项目中使用 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;

    }

显示内存泄漏如图 在此处输入图像描述

4

1 回答 1

0

CGRectMake 与泄漏无关;泄漏将来自分配两个 UILabel 和 UIImageView。根据我所看到的,您的项目没有启用 ARC,因为 ARC 会负责在此处释放您分配的对象。

检查是否启用了 ARC:

  1. 转到项目导航器
  2. 在 Project Navigator 的第一行中选择顶级项目项
  3. 在“目标”下,选择您的应用
  4. 选择编辑器顶部的“构建设置”,然后搜索“自动”
  5. 找到“Objective-C 自动引用计数”并将其设置为Yes
于 2013-09-19T08:09:28.600 回答