【发布时间】:2018-01-15 05:05:17
【问题描述】:
我有一个包含 3 种不同类型的 uitableview 单元格的表格视图。当我向下或向上滚动时,它是不稳定的。我尝试了很多方法来不让它变得波涛汹涌但失败了。
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 44;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
CD_Dates *dates = [self.cdMenuStream.dates objectAtIndex:indexPath.section];
MenuTableViewCell *tCell = [self.tableView dequeueReusableCellWithIdentifier:@"MenuTableViewCell" forIndexPath:indexPath];
switch ([self getRowTypeForIndexPath:indexPath]) {
case RowTypeMenu:
[tCell configMenuCell:dates.menu withAnimation:self.switchMenuAnimationFlag];
break;
case RowTypeAddon:
[tCell configAddonCell:dates.addon_menu withAnimation:self.switchMenuAnimationFlag];
break;
case RowTypeContent:
[tCell configContentCell:dates.content];
break;
default:
break;
}
tCell.delegate = self;
tCell.currentIndexPath = indexPath;
if (indexPath.section == 0 && indexPath.row == 0) {
tCell.csMarginTopTitleView.constant = 0;
}
[tCell setNeedsDisplay];
[tCell layoutIfNeeded];
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
cell = tCell;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat heightRow = 0;
switch ([self getRowTypeForIndexPath:indexPath]) {
case RowTypeMenu:
heightRow = 477.6667;
break;
case RowTypeAddon:
heightRow = 283.6667;
break;
case RowTypeContent:
heightRow = 187.6667;
break;
default:
break;
}
if (heightRow == 0) {
return UITableViewAutomaticDimension;
}
if (indexPath.section == 0 && indexPath.row == 0) {
heightRow = heightRow - 22.5;
}
return heightRow;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(MenuTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat horizontalOffset = -17.5;
NSString *key = [NSString stringWithFormat:@"%zd %zd", indexPath.section, indexPath.row];
if ([self.contentOffsetDictionary valueForKey:key]) {
horizontalOffset = [self.contentOffsetDictionary[key] floatValue];
}
[cell setNeedsDisplay];
[cell.collectionView setContentOffset:CGPointMake(horizontalOffset, cell.collectionView.contentOffset.y)];
[cell layoutIfNeeded];
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat heightRow = 0;
switch ([self getRowTypeForIndexPath:indexPath]) {
case RowTypeMenu:
heightRow = 477.6667;
break;
case RowTypeAddon:
heightRow = 283.6667;
break;
case RowTypeContent:
heightRow = 187.6667;
break;
default:
break;
}
if (heightRow == 0) {
return UITableViewAutomaticDimension;
}
if (indexPath.section == 0 && indexPath.row == 0) {
heightRow = heightRow - 22.5;
}
return heightRow;
}
它是一个用自定义 tableview 单元格包裹的 tableview,并且每个自定义 tableview 单元格都有一个集合视图。如果我在自定义 tableview 单元格中滚动集合视图,它不会断断续续,但是当我滚动 tableview 时。有什么办法可以让它不波涛汹涌,谢谢。
【问题讨论】:
-
是否会导致故障?
-
波涛汹涌是什么意思?问题的屏幕截图将有助于理解您的问题。
标签: ios objective-c iphone performance uitableview