UITableView
私はこのように設定されたカスタムセルを持っていますUITableView
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"CELL_IDENTIFIER";
SGCustomCell *cell = (SGCustomCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) cell = [[SGCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell = [self customizedCell:cell withPost:[postsArray objectAtIndex:indexPath.row]];
return cell;
}
このようにセルを設定しました(具体的には、この回答UITextView.text
に記載されているようにnil
- を設定します):
descriptionLabel.text = nil;
descriptionLabel.text = post.postDescription;
descriptionLabel.frame = CGRectMake(leftMargin - 4, currentTitleLabel.frame.origin.y + currentTitleLabel.frame.size.height + 10, self.frame.size.width - topMargin * 3, 100);
[descriptionLabel sizeToFit];
セルは 100% 再利用可能で、UITextView
次のように初期化されます (ご覧のとおり、特別なことは何もありません)。
descriptionLabel = [[UITextView alloc] init];
descriptionLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:11];
descriptionLabel.editable = NO;
descriptionLabel.scrollEnabled = NO;
descriptionLabel.dataDetectorTypes = UIDataDetectorTypeLink;
descriptionLabel.frame = CGRectMake(leftMargin, currentTitleLabel.frame.origin.y + currentTitleLabel.frame.size.height + 10, self.frame.size.width - topMargin * 3, 10);
[self addSubview:descriptionLabel];
しかし、テーブルに約 50 個のセルがあり、高速にスクロールすると、次のクラッシュが発生します。
Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds'
これは絶対にばかげています - 私はこの行をコメントアウトします -descriptionLabel.dataDetectorTypes = UIDataDetectorTypeLink;
そしてアプリはクラッシュしなくなります! 問題が何であるかを把握するために何時間も費やしましたが、今ではこれを簡単に理解できます。
iOS 7.0.3 でテスト済み