我有一個包含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