我不希望动画在开始更新,结束更新块为uitableview?

mkt*_*kto 81 objective-c uitableview

我有一个UITableView使用自定义表格单元格,每个单元格都有一个UIWebView.

因为UIWebView需要花时间加载,所以我想避免不惜一切代价重新加载它们.在某些情况下,我已经加载了所有单元格,但它们的高度混乱了.因此,我需要"重新布局"表而不触发"cellForRow"功能.

  1. 我绝对不能使用reloadData ...因为它会再次重新加载单元格.
  2. 我尝试了tableView.setNeedDisplay,setNeedsLayout等,它们都没有能够重新排列表格单元格
  3. 它工作的唯一方法是调用beginupdates/endupdates块,这个块能够重新启动我的表而不需要激活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)


Nei*_*tha 5

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)


hst*_*tdt 5

正在研究我的项目,但不是一个通用的解决方案。

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)