由于这一行,我有一个生涩的向下滚动问题:
NSString *text =[NSString stringWithCString:[[Text objectAtIndex:indexPath.row] cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding];
文本长度因单元格行而异。我在以下位置有这一行:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
有没有办法克服这个问题?任何帮助表示赞赏。
将文本异步加载到表视图单元格,如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *objects=[[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];
CustomCell *cell=[objects objectAtIndex:0];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSString *text =[NSString stringWithCString:[[Text objectAtIndex:indexPath.row] cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding];
dispatch_sync(dispatch_get_main_queue(), ^{
CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];
// set the string to cell here using cell object.
});
});
return cell;
}
好的,伙计们,我在我的问题上搜索了几个小时,我发现我必须预先计算我所有的 uitableviewcell 并将它们保存到 nsmutablearray 中。我不得不预先计算其单元格的高度,因为高度是动态的而不是静态的。完成所有计算后,我必须将此行添加到
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [self.CellObjects objectAtIndex:indexPath.row]; //this just loads the precomputed cell
}
而且我还必须像这样添加每个单元格的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSNumber *height=[HeightObjects objectAtIndex:indexPath.row];
CGFloat height1=[height floatValue];
return height1;
}
希望它对某人有所帮助!