不,你不必同时使用两者。您可以使用reloadCell
技术或通过beginUpdate
和endUpdate
更新单元格。
当您重新加载特定行时,内部表格视图系统会创建2个单元格,然后与新单元格进行混合。您可以删除beginUpdates
和endUpdates
,只需调用它即可更改高度。但动画不会平滑,您将观察小细胞的线条,同时从较大的细胞高度动画回来。
至于beginUpdates
和endUpdates
他们用于组插入,删除等,但它是一个古老的黑客强制调用表视图委托,并获得选定的索引更改后的高度。这种技术很好地处理高度变化动画。所以,你的代码会像
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Write the code to track the selected index path.
tableView.reloadRowsAtIndexPaths(indexPaths, withRowAnimation: UITableViewRowAnimation.Automatic)
}
OR
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView beginUpdates]; // tell the table you're about to start making changes
//Write the code to track the selected index path.
[tableView endUpdates]; // tell the table you're done making your changes
}
这不是 “一个或另一个”。它们被用于不同的目的。 'beginUpdates()'和'endUpdates()'用于将插入,删除等分组在一起,以便同时进行动画处理。他们实际上没有修改任何东西。但是如果你已经阅读过[documentation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/beginUpdates),那就应该是明确。 –
感谢您的回应!我以前在有关由beingUpdates和endUpdates方法定义的动画块中调用reloadRowsAtIndexPaths的文档中阅读了一些内容。并看看在stackoverflow类似的线程,这两个解决方案已被推荐为我想要完成的。这就是为什么我有点困惑。对不起,如果问题看起来很懒,但在阅读文档后我真的很想找一点解释。 – user3353890