0

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

它工作得非常完美,但我担心 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;
}
4

0 回答 0