[英]Reload UITableView without reloading header section
我有一个带有部分和索引标题的UITableview
。 当用户单击单元格时,高度为42的选项视图将显示在该单元格中。 为了显示该选项,我重新加载了单元格。 但是节标题也正在更新。 这给了怪异的动画。 如何仅重新加载单元格,而无需调用其他委托方法,例如heightForHeaderInSection
和viewForHeaderInSection
。
我认为您应该只更新indexPath的特定行,请尝试以下代码
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];
}
它可能会帮助您。
干杯。
在Swift 2.0及更高版本中
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.beginUpdates()
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
tableView.endUpdates()
}
有几种方法可以重新加载tableview。
重新加载整个部分,包括部分的单元格。
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
例:
[tableVIewContent reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationAutomatic];
重新加载单个/多个单元格
- (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath > )indexPaths withRowAnimation:(UITableViewRowAnimation)animation
例:
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
重新加载整个tableview。
- (void)reloadData;
//从头开始重新加载所有内容。 重新显示可见的行。 因为我们只保留有关可见行的信息,所以这很便宜。 如果表格缩小,将调整偏移量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.