Iphone UIimage通过JSON从服务器加载,在uitableview中加载缓慢

Iphone UIimage通过JSON从服务器加载,在uitableview中加载缓慢,iphone,uitableview,Iphone,Uitableview,`-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath { 我相信这个问题以前也被问过,而且很可能是你问的,因为代码非常相似 每次数据源要求其委托人创建一个新单元格时,您都在创建一个新单元格。这行代码: NSString* CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPat

`-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {


我相信这个问题以前也被问过,而且很可能是你问的,因为代码非常相似

每次数据源要求其委托人创建一个新单元格时,您都在创建一个新单元格。这行代码:

    NSString* CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row];
    UITableViewCellFixed *cell = (UITableViewCellFixed *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCellFixed alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                            reuseIdentifier:CellIdentifier] autorelease];;
    }

   NSURL *url = [NSURL URLWithString:[dict objectForKey:@"allfeeds3"]];
    NSData *data = [[NSData alloc] initWithContentsOfURL:url];
 // cell.imageView.image = [UIImage imageWithData:data];
    UIImage *tmpImage = [[UIImage alloc] initWithData:data];
    cell.imageView.image = tmpImage;

}
结果每次都会创建一个新单元格。如果每个单元格都相同(在布局方面,而不是内容方面),则可以使用单个静态NSString作为重用标识符。这样,tableview将尝试从其队列中拉出一个可重用单元格,而不是每次创建一个


此外,看起来您只是在尝试下载主线程上的数据。并且,即使单元格被重用,您也可以分配/初始化一个新的UIImageView。您需要将UITableViewCell子类化,或者在LayoutSubView中设置UIImageView,或者从nib加载它。您需要重新考虑整个方法。请小心。

这有been在这里问了很多次…请在发布您的问题之前搜索。答案已经在这里了…请检查:,
    NSString* CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row];
    UITableViewCellFixed *cell = (UITableViewCellFixed *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCellFixed alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                            reuseIdentifier:CellIdentifier] autorelease];;
    }

   NSURL *url = [NSURL URLWithString:[dict objectForKey:@"allfeeds3"]];
    NSData *data = [[NSData alloc] initWithContentsOfURL:url];
 // cell.imageView.image = [UIImage imageWithData:data];
    UIImage *tmpImage = [[UIImage alloc] initWithData:data];
    cell.imageView.image = tmpImage;

}
 NSString* CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row];