我知道,这个问题被问了好几次,每次都被回答超过 1 次,但没有一个,这些解决方案帮助了我自己!
当我的 TableView 打开时,我可以看到一行文本,而不是 >10!所以我向下滚动,2 个单元格后它以正确的方式呈现!如果我再次向上滚动,我可以看到只有这一行的单元格,也正确地呈现了一切! 所以,这是我的问题:我的代码出了什么问题?!
这是我的 cellForRowAtIndexPath:
NSString *CellIdentifier = @"Cell";
AACTickerYellowCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[AACTickerYellowCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString * text = [self getTextAtIndex:indexPath];
CGSize size = [self frameForText:text sizeWithFont:nil constrainedToSize:CGSizeMake(260.0f, CGFLOAT_MAX)];
[cell.textView setFrame:CGRectMake(10, 5, 260, size.height + 20)];
cell.textView.text = text;
return cell;
最佳答案
像那样尝试,你的问题就会消失:
NSString *CellIdentifier = @"Cell";
AACTickerYellowCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[AACTickerYellowCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString * text = [self getTextAtIndex:indexPath];
dispatch_async(dispatch_get_main_queue(), ^{
CGSize size = [self frameForText:text sizeWithFont:nil constrainedToSize:CGSizeMake(260.0f, CGFLOAT_MAX)];
[cell.textView setFrame:CGRectMake(10, 5, 260, size.height + 20)];
cell.textView.text = text;
});
return cell;
关于ios - TableView 在滚动时更改单元格内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19507236/