[英]UITableView: How to attach a footer to a section with grouped dynamic prototype cells?
[英]UITableView grouped section footer not updating after reload
在分組的UITableView中,我有3個或2個部分(取決於數據源)。 我正在嘗試通過以下方式重新加載最后一部分:
dispatch_async(dispatch_get_main_queue(), ^{
[UIView performWithoutAnimation:^{
[feedDetailTB reloadSections:[NSIndexSet indexSetWithIndex:feedDetailTB.numberOfSections-1] withRowAnimation:UITableViewRowAnimationNone];
}];
});
首先,頁腳永遠不會消失。 數據源基本上會跟蹤是否有更多注釋(簡單加載更多功能)。 在viewForFooterInSection
,當所有注釋均已加載時,我僅return nil
。
但是,正如您在GIF中看到的那樣,首先, loading
按鈕停留在該位置。 它甚至可以訪問並且有效。 當我向上滾動時,它消失了,並且可以在底部看到它,這是正確的。 但是,在重新加載所有評論之后,它應該消失了,但可悲的是它停留在那里。
如果我使用reloadData
可以正常工作。 但是我無法使用它,因為我還有其他部分,不需要重新加載。
其次,即使我使用了UITableViewRowAnimationNone
,行項目也有奇怪的動畫/閃爍。 在GIF中不可見
您應該根據自己的邏輯實現“ isTheLastSection”
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if (isTheLastSection) {
return 40;
}
return 0;
}
為了將新行添加到節中,您必須使用insertRowsAtIndexPaths
而不僅僅是將新對象添加到數據源並重新加載節。
這是代碼:
NSMutableArray *newCommentsIndexPath = [[NSMutableArray alloc] init];
for (NSInteger i = currentCount; i < (_postDetailDatasource.commentsFeedInfo.allCommentsArray.count + serverComments.count); i ++)
{
NSIndexPath *idxPath = [NSIndexPath indexPathForRow:i inSection:sectionNumber];
[newCommentsIndexPath addObject:idxPath];
}
[_postDetailDatasource.commentsFeedInfo.allCommentsArray addObjectsFromArray:serverComments];
[feedDetailTB beginUpdates];
[feedDetailTB insertRowsAtIndexPaths:newCommentsIndexPath withRowAnimation:UITableViewRowAnimationFade];
[feedDetailTB endUpdates];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.