我在我的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 上测试通过
[postsArray objectAtIndex:indexPath.row]
的问题吗? - calimarkus