使用UITmageView在UITableViewCell中的内存消耗

时间:2013-07-16 09:55:52

标签: ios uitableview memory-leaks uiimage

我正在开发一个仅从文件夹加载图像的应用程序(而不是从任何Web服务器加载)。

它的工作非常完美,但我担心UITableView的内存消耗。

每当我滚动UITableView时, 内存已分配且从未取消分配
我正在使用所有对象的发布。

请参阅下面的代码。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OtherThingsName"];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"OtherThingsName"];
    }

    if ([cell viewWithTag:123]!=nil) {
        NSLog(@"Removed");
        [[cell viewWithTag:123] removeFromSuperview];
        [[cell viewWithTag:1231] removeFromSuperview];
        [[cell viewWithTag:1232] removeFromSuperview];
    }

    UIView *viewInTableCell=nil;
    UILabel *lblTitleInCell=nil;
    UIImageView *imageInCell=nil;

    viewInTableCell = [[UIView alloc] initWithFrame:cell.bounds];
    lblTitleInCell = [[UILabel alloc] initWithFrame:CGRectMake(120, (cell.bounds.size.height/2), 190, 30)];
    imageInCell = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 80)];

    [lblTitleInCell setText:[self.arrayOfOtherThings objectAtIndex:indexPath.row]];
    [imageInCell setImage:[UIImage imageNamed:[self.arrayOfImages objectAtIndex:indexPath.row]]];

    [viewInTableCell setTag:123];
    [lblTitleInCell setTag:1231];
    [imageInCell setTag:1232];

    [viewInTableCell addSubview:lblTitleInCell];
    [viewInTableCell addSubview:imageInCell];

    [cell addSubview:viewInTableCell];

    //    cell.textLabel.text = [self.arrayOfOtherThings objectAtIndex:indexPath.row];

    lblTitleInCell = nil;
    imageInCell = nil;
    viewInTableCell = nil;

    [lblTitleInCell release];
    [imageInCell release];
    [viewInTableCell release];

    return cell;
}

0 个答案:

没有答案