有没有办法重新加载特定的UITableView
具有多个带有动画部分的单元格?
我一直在使用:
self.TheTableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: UITableViewRowAnimation.Right)
但这会为该部分中的所有单元格设置动画。另一种选择是使用:
self.TheTableView.reloadRowsAtIndexPaths(<#indexPaths: [AnyObject]#>,
withRowAnimation: <#UITableViewRowAnimation#>)
EDIT:
使用 reloadRowsAtIndexPaths 后
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效更新:第 1 节中的行数无效。更新 (5) 后现有节中包含的行数必须等于该节中包含的行数更新前的部分 (4),加上或减去从该部分插入或删除的行数(0 插入,0 删除)以及加上或减去移入或移出该部分的行数(0 移入,0 移动出去)。'
尝试找到一种通过将对象附加到数组中来重新加载表格视图的平滑方法。
在 reloadRowsAtIndexPaths 之前调用 TableView.reloadData() 有效,但动画有问题。还有另一种方法吗?
为什么不直接重新加载单元格呢? indexPath 包含节和行,因此只需跟踪要重新加载的节并填充该数组中的索引即可。
var indexPath1 = NSIndexPath(forRow: 1, inSection: 1)
var indexPath2 = NSIndexPath(forRow: 1, inSection: 2)
self.tableView.reloadRowsAtIndexPaths([indexPath1, indexPath2], withRowAnimation: UITableViewRowAnimation.Automatic)
根据您的评论,您希望更改数组并让 tableView 在更改中设置动画。如果是这种情况,您应该考虑对 UITableViews 甚至使用 beginUpdates() 和 endUpdates()NSFetchedResultController https://developer.apple.com/library/ios/documentation/CoreData/Reference/NSFetchedResultsController_Class/所以它可以干净地处理所有更新动画。
self.tableView.beginUpdates()
// Insert or delete rows
self.tableView.endUpdates()
我建议使用NSFetchedResultController https://developer.apple.com/library/ios/documentation/CoreData/Reference/NSFetchedResultsController_Class/如果您使用 Core Data,因为它简化了整个过程。否则,您必须自己处理更改。换句话说,如果您的数组发生更改,您需要使用 beginUpdates() 和 endUpdates() 手动删除或插入表视图中的行。
如果您不使用 Core Data,请学习this https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html掌握这一切是如何处理的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)