已解决
self.view 图层上有阴影。删除它后,tableview 滚动流畅(56-59fps)。
我遇到的问题很奇怪。
我正在构建一个基于 UITableView 的 Twitter 应用程序。优化 TableView 加载和滚动后,我在 iPad 2 和 iPhone 4S 上测试了应用程序(相同的代码和相同的 UI)。在 iPad 2 上,我得到了 56-59fps 的平滑滚动动画。但是在 iPhone 4S 上,我只有 43-49fps 的滚动动画,这很糟糕。
这似乎不是由 Retina 显示屏引起的。从单元格中删除所有图像后,问题仍然存在。下面是cellForRowAtIndexPath的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// fetch note from the fetched results controller
Note *note = [self.fetchedResultsController objectAtIndexPath:indexPath];
if ([note.photos count] > 0) {
static NSString *CellIdentifier = @"Photo Cell";
PhotoCell *cell = (PhotoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[PhotoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
} else {
[cell clearContents];
}
NSNumber *currentRowNumber = [NSNumber numberWithInt:indexPath.row];
// check if the photos of this cell has been pre loaded
NSDictionary *coverImages = [self.coverImagesForNotes objectForKey:currentRowNumber];
if (coverImages == nil) {
if (self.tableView.dragging == NO && self.tableView.decelerating == NO) {
coverImages = [self loadCoverImagesForCell:indexPath photos:note.photos];
[self.coverImagesForNotes setObject:coverImages forKey:currentRowNumber];
}
}
// assign contents to the cell
[self compositeContentView:cell forNote:note rowNumber:indexPath.row];
// refine
unsigned textContentHeight = [[self.cellTextHeightDict objectForKey:currentRowNumber] integerValue];
unsigned currentPageNumber = [self currentPageNumberAtRow:indexPath.row];
[cell initPhotoVideoView:textContentHeight photos:note.photos coverImages:coverImages showPage:currentPageNumber rowNumber:indexPath.row];
cell.delegate = self;
return cell;
} else {
static NSString *CellIdentifier = @"Simple Cell";
BaseCell *cell = (BaseCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[OneViewBaseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// assign contents to the cell
[self compositeContentView:cell forNote:note rowNumber:indexPath.row];
return cell;
}
}
感谢您的回答。
最佳答案
您是否在表格 View 单元格中使用图像?这在视网膜显示器上会更昂贵。此外,如果您正在使用图像,请尝试将它们加载到后台线程中,这将减少延迟。
如果您不使用图像,那么您真的应该看看您是如何创建单元格的,请发布 tableView:cellForRowAtIndexPath:
方法实现
关于ios - iPad 2 和 iPhone 4s 上不同的 UITableView 滚动性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12822438/