を消える: - ユーザープレススタートボタンを - イメージがダウンロードされるだけでなく、テーブルビューでのUITableView - セル内のすべてのデータは、私は次の特性を持っているcustomCellとテーブルビュー、持って
@interface CustomTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (weak, nonatomic) IBOutlet UILabel *nameOfImage;
@property (weak, nonatomic) IBOutlet UIButton *start;
@property (weak, nonatomic) IBOutlet UIButton *stop;
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@property (weak, nonatomic) IBOutlet UILabel *realProgressStatus;
をrealProgressStatusのprogressViewは現在の状況を反映します。この段階ではすべてが完璧に機能しますが、スクロールテーブルビューでセルに戻ると、データで既に満たされています。すべての情報が消えました(nameOfImageを除いて、別に設定しました)。 私はCustomTableViewCellクラスに次のメソッドを実装し:
-(void)prepareForReuse
{
[super prepareForReuse];
self.progressView.progress = 0.1;
self.realProgressStatus.text = @"";
self.image.image = [UIImage imageNamed:@"placeholder"];
}
を私はイメージが既にダウンロードセルの数を節約する新しいプロパティNSMutableSet self.tagsOfCellsを実装しました。 私はテーブルビューの方法で変更を加えることを試みたが、効果は同じである:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* PlaceholderCellIdentifier = @"Cell";
CustomTableViewCell *customCell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier forIndexPath:indexPath];
customCell.delegate = self;
customCell.cellIndex = indexPath.row;
if (!customCell)
{
customCell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"cell"];
}
else
{
NSNumber *myNum = [NSNumber numberWithInteger:indexPath.row];
if (![self.tagsOfCells containsObject:myNum])
{
NSLog(@"Row: %ld",(long)indexPath.row);
UIImage *img = [UIImage imageNamed:@"placeholder"];
customCell.realProgressStatus.text = @"";
customCell.progressView.progress = 0.1;
customCell.image.image = img;
[customCell setNeedsLayout];
}
}
if (indexPath.row % 2 == 0)
customCell.backgroundColor = [UIColor grayColor];
else
customCell.backgroundColor = [UIColor darkGrayColor];
customCell.nameOfImage.text = self.names[indexPath.row];
return customCell;
}
はEDIT:
私は画像をダウンロード中のいずれかの方法でself.tagsOfCellsを移入、ここでの方法は次のとおりです。
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
self.customCell.realProgressStatus.text = @"Downloaded";
UIImage *img = [UIImage imageWithData:self.imageData];
self.customCell.image.image = img;
self.customCell.tag = self.selectedCell;
[self.savedImages setObject:img forKey:self.customCell.nameOfImage.text];
NSNumber *myNum = [NSNumber numberWithInteger:self.selectedCell];
[self.tagsOfCells addObject:myNum];
}
ご協力いただきありがとうございます。
ありがとうございます。私はForReuseメソッドの準備を削除し、cellForRowAtIndexPathで書かれたものだけを使用しますが、データは消えます。条件 - if(![self.tagsOfCells containsObject:myNum])をチェックしても、このセクションには入力されないので、データを上書きしないでください。何らかの理由でそれを行います。私は間違ったことを理解できません.... – Melany
ありがとう)))最終的には動作します!ちなみに、私はあなたのアドバイスが冒険になる可能性があると思います。事前にありがとう))) – Melany