mkt*_*kto 81 objective-c uitableview
我有一个UITableView使用自定义表格单元格,每个单元格都有一个UIWebView.
因为UIWebView需要花时间加载,所以我想避免不惜一切代价重新加载它们.在某些情况下,我已经加载了所有单元格,但它们的高度混乱了.因此,我需要"重新布局"表而不触发"cellForRow"功能.
我怎样才能解决我的问题?
Evg*_*kov 204
[UIView setAnimationsEnabled:NO];
[tableView beginUpdates];
[tableView endUpdates];
[UIView setAnimationsEnabled:YES];
Run Code Online (Sandbox Code Playgroud)
Dmi*_*riy 55
使用块的另一种方法
OBJ-C
[UIView performWithoutAnimation:^{
[self.tableView beginUpdates];
[self.tableView endUpdates];
}];
Run Code Online (Sandbox Code Playgroud)
迅速
UIView.performWithoutAnimation {
tableView.beginUpdates()
tableView.endUpdates()
}
Run Code Online (Sandbox Code Playgroud)
Swifties 我必须执行以下操作才能使其正常工作:
// Sadly, this is not as simple as calling:
// UIView.setAnimationsEnabled(false)
// self.tableView.beginUpdates()
// self.tableView.endUpdates()
// UIView.setAnimationsEnabled(true)
// We need to disable the animations.
UIView.setAnimationsEnabled(false)
CATransaction.begin()
// And we also need to set the completion block,
CATransaction.setCompletionBlock { () -> Void in
// of the animation.
UIView.setAnimationsEnabled(true)
}
// Call the stuff we need to.
self.tableView.beginUpdates()
self.tableView.endUpdates()
// Commit the animation.
CATransaction.commit()
Run Code Online (Sandbox Code Playgroud)
正在研究我的项目,但不是一个通用的解决方案。
let loc = tableView.contentOffset
UIView.performWithoutAnimation {
tableView.reloadData()
tableView.layoutIfNeeded()
tableView.beginUpdates()
tableView.endUpdates()
tableView.layer.removeAllAnimations()
}
tableView.setContentOffset(loc, animated: true)//animation true may perform better
Run Code Online (Sandbox Code Playgroud)