我正在尝试制作 UITableView。但是我的表格错误是,当它滚动时(当一个单元格被隐藏然后再次显示时)它会重置选项卡并再次从服务器加载图像。我怎样才能让它不加载图像或保留以前的单元格
static NSString *myIdentifier = @"myIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myIdentifier];
backImage = [[UIImageView alloc] initWithFrame:CGRectMake(2, 4, 300, 62)];
userDp = [[UIImageView alloc] initWithFrame:CGRectMake(11, 10, 50, 50)];
name = [[UILabel alloc] initWithFrame:CGRectMake(67, 12, 176, 20)];
name.font = [UIFont fontWithName:@"HelveticaLTStd-Bold" size:12];
CustomActivityViewer *imgIndicator = [[CustomActivityViewer alloc] initWithView:userDp];
[imgIndicator startAnimating];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0),^{
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", IMAGE_URL, player.imagePath]]]];
dispatch_async(dispatch_get_main_queue(), ^{
[imgIndicator stopAnimating];
if (img != nil)
userDp.image = img;
[imgIndicator stopAnimating];
});
});
[name setShadowColor:[UIColor blackColor]];
[name setShadowOffset:CGSizeMake(1, 1)];
name.textColor = [UIColor colorWithRed:1.0 green:0.824 blue:0 alpha:1.0];
cell.accessoryType = UITableViewCellAccessoryNone;
[cell setSelectionStyle:UITableViewCellEditingStyleNone];
cell.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:backImage];
[cell.contentView addSubview:userDp];
[cell.contentView addSubview:name];
return cell;
}
如果我放置 if (cell!= nil) 则单元格重复自身。
该怎么办?
PS 在 iPhone 自己的教程之一中,我看到了类似 cell.contentView 设置带有标签的项目,然后如果单元格不为零,则使用标签调用视图。我找不到那个教程。万一有人知道