我有一个包含4张照片,我从网络中这些照片,但问题是,当我向下滚动,这些照片被再次下载 如何下载照片?
中的UITableView这是代码一个UITableViewCell:
ITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellPhoto"];
if (cell == nil) {
NSArray *nibObject = [[NSBundle mainBundle] loadNibNamed:@"CustomCellThumbnails" owner:self options:nil];
cell = [nibObject objectAtIndex:0];
}
// Get the photos
int getPhotos = indexPath.row * 4;
for (int i = 1; i <= 4; i++) {
if (getPhotos < [imageArray count])
{
UIButton *imageButton = (UIButton*)[cell viewWithTag:i];
NSString *url = [imageArray objectAtIndex:getPhotos];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.siteweb.com%@",url]]];
UIImage *imageFieldProfile = [[UIImage alloc] initWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
// Set the phoyo to the UIButton
[imageButton setBackgroundImage:imageFieldProfile forState:UIControlStateNormal];
[imageFieldProfile release];
// Set the corner of UIButton
[imageButton.layer setCornerRadius:5.0];
[imageButton.layer setMasksToBounds:YES];
imageButton.tag = getPhotos;
});
});
[imageButton addTarget:self action:@selector(displayPhoto:) forControlEvents:UIControlEventTouchUpInside];
}
getPhotos ++;
}
但是,如果我有一个自定义的UITableViewCell在笔尖文件如何创建与initWithStyle一个UITableViewCell:reuseIdentifier:usingCacheTable: – 2011-12-31 20:09:23
不知道 - 考虑将其添加为一个属性,使用'[细胞setMyCache:]'代替。 – 2011-12-31 20:11:28