テーブルビュー セルのスクロール速度に問題があります。セルをデキューして再利用するとハングアップすることがわかります。以下は、セルを作成するために使用する私のコードです。私は 2 つのカスタム セルを使用しています。1 つのセルは画像がある場合で、もう 1 つのセルはユーザーが画像を添付しなかった場合です。どんな洞察も大歓迎です。また、セル間にスペースを追加したかったので、基本的に単一のセルを含む新しいセクションを作成しました。これが、私のコード indexPath.section に常に表示される理由です。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *imageCell = @"ShameImage";
static NSString *noImageCell = @"ShameNoImageCell";
static NSString *noCell = @"NoCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:noCell];
if ([[blobID objectAtIndex:indexPath.section] isEqualToNumber:[NSNumber numberWithInt:1]])
{
ShameViewCell *cell = (ShameViewCell *)[self.tableView dequeueReusableCellWithIdentifier:imageCell];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ShameImageCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
CALayer *cellImageView = [cell.imageView layer];
[cellImageView setMasksToBounds:YES];
[cellImageView setCornerRadius:10.0];
IndicatorImageView *iiv = [[IndicatorImageView alloc] initWithFrame:CGRectMake(0, 0, 88, 88)];
[iiv setShameID:[[shameID objectAtIndex:indexPath.section] stringValue]];
iiv.tag = 999;
[iiv loadImageFromURL];
[cell.imageView addSubview:iiv];
cell.imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tapImage = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(openPicture:)];
tapImage.numberOfTapsRequired = 1;
[cell.imageView addGestureRecognizer:tapImage];
[cell.contentView.layer setCornerRadius:10];
[cell.contentView setBackgroundColor:[UIColor blackColor]];
[cell.contentView setAlpha:0.7f];
UIColor *insideColor = [UIColor colorWithRed:color_red green:color_green blue:color_blue alpha:1];
cell.lastShame.contentInset = UIEdgeInsetsMake(-11, -8, 0, 0);
[cell.lastShame setTextColor:insideColor];
[cell.lastShame setFont:[UIFont fontWithName:text_font_name size:14]];
cell.lastShame.text = [userShame objectAtIndex:indexPath.section];
[cell.shameDate setTextColor:insideColor];
[cell.shameDate setFont:[UIFont fontWithName:text_font_name size:11]];
cell.shameDate.text = [createDt objectAtIndex:indexPath.section];
[cell.userLabel setTextColor:insideColor];
[cell.userLabel setFont:[UIFont fontWithName:text_font_name size:11]];
cell.userLabel.text = [@"Post By: " stringByAppendingString:[userName objectAtIndex:indexPath.section]];
[cell.lastShame setBackgroundColor:[UIColor clearColor]];
return cell;
}
}else
{
ShameNoImage *cell = (ShameNoImage *)[self.tableView dequeueReusableCellWithIdentifier:noImageCell];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ShameNoImageCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
CALayer *cellImageView = [cell.imageView layer];
[cellImageView setMasksToBounds:YES];
[cellImageView setCornerRadius:10.0];
[cellImageView setBorderWidth:1.0];
[cellImageView setBorderColor:[[UIColor whiteColor] CGColor]];
[cell.contentView.layer setCornerRadius:10];
[cell.contentView setBackgroundColor:[UIColor blackColor]];
[cell.contentView setAlpha:0.7f];
UIColor *insideColor = [UIColor colorWithRed:color_red green:color_green blue:color_blue alpha:1];
cell.shameLabel.contentInset = UIEdgeInsetsMake(-11, -8, 0, 0);
[cell.shameLabel setTextColor:insideColor];
[cell.shameLabel setFont:[UIFont fontWithName:text_font_name size:14]];
cell.shameLabel.text = [userShame objectAtIndex:indexPath.section];
[cell.dateLabel setTextColor:insideColor];
[cell.dateLabel setFont:[UIFont fontWithName:text_font_name size:11]];
cell.dateLabel.text = [createDt objectAtIndex:indexPath.section];
[cell.userLabel setTextColor:insideColor];
[cell.userLabel setFont:[UIFont fontWithName:text_font_name size:11]];
cell.userLabel.text = [@"Post By: " stringByAppendingString:[userName objectAtIndex:indexPath.section]];
[cell.shameLabel setBackgroundColor:[UIColor clearColor]];
return cell;
}
}
return cell;
}