我想显示一个包含多个部分的表,最初只显示3个部分的元素。当用户点击部分页脚时,部分页脚会丢失(变为零),并且该部分的所有元素都将显示给用户。
因此,当用户点击部分页脚时,我会调用以下代码:
-(void)loadMoreRowsInSection:(NSInteger)section {
[groupStates replaceObjectAtIndex:section withObject:[NSNumber numberWithBool:YES]];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:NO];
}
我有以下代码来显示部分页脚:
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
int count = [[(NSDictionary*)[filters objectAtIndex:section] valueForKeyPath:@"values.value"] count];
if (count>3&&![[groupStates objectAtIndex:section] boolValue]) {
LoadMoreFooter* loadMoreFooter = [[LoadMoreFooter alloc] initWithParent:self Section:section];
return [loadMoreFooter view];
}
else return nil;
}
当用户点击部分页脚并调用loadMoreRowsInSection函数时,将重新加载此部分,但该部分的当前行将消失。当我向上滚动时,使行离开屏幕再次出现,行再次出现。
如果我拨打reloadData
而不是reloadSections:withRowAnimation:
,则没有任何问题,但重新加载所有表格似乎不是一个好主意。另外,reloadTable中没有动画。
有没有人遇到过这个问题?
答案 0 :(得分:24)
从某种意义上说,这是一个“静态”单元吗?在这种情况下,问题可能是这样的:
当您进行动画重新加载时,表格视图将淡出现有单元格,同时淡入新单元格。问题是,当“新”单元格与旧单元格完全相同时,同一单元格将同时淡入和淡出!在您的情况下,淡出动画优先,单元格被隐藏。
以下是一些可能的解决方案:
而不是静态单元格,有一个可重复使用的“包装单元格”子类 - 一个单元,其唯一目的是包含一个包装视图。然后,保持对视图的静态引用,并将它们添加到cellForRowAtIndexPath:
避免重新加载静态单元格的索引路径 - 改为[UIView transitionWithView:self.myStaticCell duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:nil]
答案 1 :(得分:6)
我也有这个问题。我改为使用UITableViewRowAnimationNone
,但由于某种原因(reloadData
没有这样做)仍会为该部分设置动画,但它也会在动画后正确显示。
答案 2 :(得分:4)
在调用reloadData
后添加对reloadSections:withRowAnimation:
的调用可以解决消失的单元格问题,而不会影响动画。
答案 3 :(得分:1)
我遇到了一个类似的问题,即标题标题会被粘贴在任何地方。虽然即使在屏幕上滚动/关闭我的问题仍然存在:
我找到解决方法的唯一方法就是使用reloadData
代替reloadSections:withRowAnimation:
。
答案 4 :(得分:0)
我的错误是:我有一个包含多个部分的TableView。当我选择一个用于展开的部分(并显示单元格)时,隐藏了上面的其他部分。
我将标题视为单元格。
我没有reloadData()
的解决方案:
inside override func viewDidLoad()
方法我正在使用此代码:
tableTeams.registerNib(UINib(nibName: "header", bundle: nil ),
forCellReuseIdentifier: "HeaderCell")
但我应该用这个:
tableTeams.registerNib(UINib(nibName: "header", bundle: nil),
forHeaderFooterViewReuseIdentifier: "HeaderCell")
和func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
内部,我会使用此代码:
func tableView(tableView: UITableView, viewForHeaderInSection section:
Int) -> UIView? {
let cell = tableView.dequeueReusableHeaderFooterViewWithIdentifier("HeaderCell")
as! CustomHeaderUiView
我希望这有帮助!