gpt4 book ai didi

ios - UITableView 快速向上滚动时不渲染单元格

转载 作者:行者123 更新时间:2023-12-01 16:28:21 24 4
gpt4 key购买 nike

当我在表格 View 中快速向上滚动时,它的一些单元格开始不显示。
从下图中可以看出,我的 tableview 没有显示它的一些单元格。

enter image description here

我检查了我的 cellforrowatindexpath,它似​​乎通常被所有 uitableviewcells 调用。你知道从哪里开始调试是问题吗?

这是我的 Storyboard配置:

enter image description here

这是我为调试问题而编写的一小部分代码,但是只有第一个 NSLog 被打印出来,一切似乎都还好:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CoreDataTVCell *cell = (CoreDataTVCell *)[tableView dequeueReusableCellWithIdentifier:self.cellIdentifier forIndexPath:indexPath];
NSLog(@"Cell row: %ld section: %ld", (long)indexPath.row, (long)indexPath.section);

@try {
cell.managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
[cell updateCell];
}
@catch (NSException *exception) {
NSLog(@"Object not found: %@", exception.callStackSymbols);
}

if(!cell)
{
NSLog(@"Cell not found");
}

return cell;
}

同样的问题也发生在具有 2 个单元标识符(一个用于标题,一个用于其他行)的更简单的 TVC 上:

enter image description here

这是我通过打印可见单元格(不包括第一个单元格)得到的:

enter image description here
2015-11-19 17:34:28.430 XXX[7483:3224955] ADA APENNINE - <CustomerTVCell: 0x15601e000; baseClass = UITableViewCell; frame = (0 240; 768 120); clipsToBounds = YES; hidden = YES; autoresize = W; layer = <CALayer: 0x1557bdf50>>
2015-11-19 17:34:28.431 XXX[7483:3224955] ADA APENNINE - <CustomerTVCell: 0x15601e000; baseClass = UITableViewCell; frame = (0 240; 768 120); clipsToBounds = YES; hidden = YES; autoresize = W; layer = <CALayer: 0x1557bdf50>>
2015-11-19 17:34:28.431 XXX[7483:3224955] AMED - <CustomerTVCell: 0x156036a00; baseClass = UITableViewCell; frame = (0 480; 768 120); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x1557b68e0>>
2015-11-19 17:34:28.432 XXX[7483:3224955] AMED - <CustomerTVCell: 0x156036a00; baseClass = UITableViewCell; frame = (0 480; 768 120); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x1557b68e0>>
2015-11-19 17:34:28.432 XXX[7483:3224955] AMPARO - <CustomerTVCell: 0x1560dc400; baseClass = UITableViewCell; frame = (0 720; 768 120); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x1556e7980>>
2015-11-19 17:34:28.433 XXX[7483:3224955] AMPARO - <CustomerTVCell: 0x1560dc400; baseClass = UITableViewCell; frame = (0 720; 768 120); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x1556e7980>>
2015-11-19 17:34:28.433 XXX[7483:3224955] ADA APENNINE - <CustomerTVCell: 0x15601e000; baseClass = UITableViewCell; frame = (0 240; 768 120); clipsToBounds = YES; hidden = YES; autoresize = W; layer = <CALayer: 0x1557bdf50>>

在这种情况下有 7 行可见,但似乎其中一些是重复的,而另一些则不存在。

这是应该显示的内容:
2015-11-19 17:45:50.314 X[7483:3224955] Cell row: 0 section: 0
2015-11-19 17:45:50.318 X[7483:3224955] Customer: A LA MODE

2015-11-19 17:45:50.321 X[7483:3224955] Cell row: 1 section: 0
2015-11-19 17:45:50.322 X[7483:3224955] Customer: ADA APENNINE

2015-11-19 17:45:50.325 X[7483:3224955] Cell row: 2 section: 0
2015-11-19 17:45:50.326 X[7483:3224955] Customer: ALTON

2015-11-19 17:45:50.329 X[7483:3224955] Cell row: 3 section: 0
2015-11-19 17:45:50.330 X[7483:3224955] Customer: AMED

2015-11-19 17:45:50.337 X[7483:3224955] Cell row: 4 section: 0
2015-11-19 17:45:50.338 X[7483:3224955] Customer: AMIRA

2015-11-19 17:45:50.360 X[7483:3224955] Cell row: 5 section: 0
2015-11-19 17:45:50.361 X[7483:3224955] Customer: AMPARO

2015-11-19 17:45:50.370 X[7483:3224955] Cell row: 6 section: 0
2015-11-19 17:45:50.371 X[7483:3224955] Customer: AMPARO

最佳答案

警告:这不是解决方案,它只是一种解决方法!

在用户快速向上滚动时重新加载数据会有所帮助。

特性:

@property (nonatomic) CGPoint lastOffset;
@property (nonatomic) NSTimeInterval lastOffsetCapture;
@property (nonatomic) BOOL isScrollingFast;

方法:
#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGPoint currentOffset = scrollView.contentOffset;
NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];

NSTimeInterval timeDiff = currentTime - self.lastOffsetCapture;
if(timeDiff > 0.1) {
CGFloat distance = currentOffset.y - self.lastOffset.y;

CGFloat scrollSpeedNotAbs = (distance * 10) / 1000; //in pixels per millisecond

//quickly scroll up
if (scrollSpeedNotAbs < - 3.5) {
self.isScrollingFast = YES;
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
NSLog(@"Fast!");
}

self.lastOffset = currentOffset;
self.lastOffsetCapture = currentTime;
}
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate) {
[self scrollingFinish];
}
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[self scrollingFinish];
}

- (void)scrollingFinish {
//enter code here
if(self.isScrollingFast){
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
self.isScrollingFast = NO;
}
}

请记住在您的 TVC 中声明 < UIScrollViewDelegate >。

关于ios - UITableView 快速向上滚动时不渲染单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33808245/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com