Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableViewCell中UIImageView的内存消耗_Ios_Uitableview_Memory Leaks_Uiimage - Fatal编程技术网

Ios UITableViewCell中UIImageView的内存消耗

Ios UITableViewCell中UIImageView的内存消耗,ios,uitableview,memory-leaks,uiimage,Ios,Uitableview,Memory Leaks,Uiimage,我正在开发一个应用程序,只从文件夹加载图像(不从任何web服务器) 它的工作非常完美,但我担心UITableView会消耗内存 每当我滚动UITableView时,内存被分配,并且从不释放 我在所有对象上使用释放 请看下面我的代码 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [t

我正在开发一个应用程序,只从文件夹加载图像(不从任何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;
}

请找到一个好的
UITableView
教程并从那里开始。你所做的是错误的。当屏幕上出现相同的子视图时,您会一次又一次地向单元格中添加相同的子视图。感谢回复@Desdenova,但在使用它们之后,我还将它们设置为“nil”。所以,它并没有以任何方式释放内存?不像你们想象的那个样,因为细胞本身持有内存。您需要使用自定义
UITableViewCell
。好的,谢谢。。我找到了一本教程@德斯德诺瓦诺问题。祝你好运