tableView.reloadData和tableView.reloadRows之间有什么区别? [英] What's the difference between tableView.reloadData and tableView.reloadRows?

查看:1739
本文介绍了tableView.reloadData和tableView.reloadRows之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tableView.reloadData() tableView.reloadRows(at:[IndexPath],有:.none)之间有什么区别



我知道单元格会在 tableView.reloadData()




我尝试了以下内容。

  cell.count = 2 

indexPath = [0,0] [0,1]

  tableView.reloadRows(at:[[0,0] as IndexPath],with:.none)
tableView.reloadRows(at: [[0,1] as IndexPath],带:.none)






然而,它没有按预期结果。



使用单元格重新加载所有 tableView.reloadRows()并使用<$ c $重新加载之间的行为是否不同c> tableView.reloadData()?

解决方案

查看苹果文档 -



1。 reloadData():



重新加载表格视图的行和部分。



说明:调用此方法重新加载用于构造表的所有数据,包括单元格,节页眉和页脚,索引数组等。为了提高效率,表视图仅重新显示可见的行。如果表因重新加载而缩小,它会调整偏移量。表视图的委托或数据源在希望表视图完全重新加载其数据时调用此方法。它不应该在插入或删除行的方法中调用,尤其是在通过调用beginUpdates()和endUpdates()实现的动画块中。



2 。 reloadRows(at:with :):



使用动画效果重新加载指定的行。



描述



重新加载行会导致表视图向其数据源询问该行的新单元格。该表为新单元设置动画,因为它为旧行设置了动画。如果要提醒用户单元格的值正在更改,请调用此方法。但是,如果通知用户并不重要 - 也就是说,您只想更改单元格显示的值 - 您可以获取特定行的单元格并设置其新值。



当在beginUpdates()和endUpdates()方法定义的动画块中调用此方法时,它的行为与deleteRows(at:with :)类似。 UITableView传递给方法的索引在任何更新之前在表视图的状态中指定。无论动画块中的插入,删除和重新加载方法调用的顺序如何,都会发生这种情况。



https://developer.apple.com/documentation/uikit/uitableview/1614862-reloaddata
https://developer.apple.com/documentation/uikit/uitableview/1614935-reloadrows


What is the difference between tableView.reloadData() and tableView.reloadRows(at: [IndexPath],with: .none)?

I know that cells will reload everything after tableView.reloadData()


I tried the following.

cell.count = 2

indexPath = [0,0] and [0,1]

tableView.reloadRows(at: [[0,0] as IndexPath],with: .none)
tableView.reloadRows(at: [[0,1] as IndexPath],with: .none)


However, it did not result as expected.

Does the behavior differ between reloading all of tableView.reloadRows() with cells and reloading with tableView.reloadData()?

解决方案

Check out the apple documentation for this -

1. reloadData() :

Reloads the rows and sections of the table view.

Description : Call this method to reload all the data that is used to construct the table, including cells, section headers and footers, index arrays, and so on. For efficiency, the table view redisplays only those rows that are visible. It adjusts offsets if the table shrinks as a result of the reload. The table view’s delegate or data source calls this method when it wants the table view to completely reload its data. It should not be called in the methods that insert or delete rows, especially within an animation block implemented with calls to beginUpdates() and endUpdates().

2. reloadRows(at:with:) :

Reloads the specified rows using an animation effect.

Description:

Reloading a row causes the table view to ask its data source for a new cell for that row. The table animates that new cell in as it animates the old row out. Call this method if you want to alert the user that the value of a cell is changing. If, however, notifying the user is not important—that is, you just want to change the value that a cell is displaying—you can get the cell for a particular row and set its new value.

When this method is called in an animation block defined by the beginUpdates() and endUpdates() methods, it behaves similarly to deleteRows(at:with:). The indexes that UITableView passes to the method are specified in the state of the table view prior to any updates. This happens regardless of ordering of the insertion, deletion, and reloading method calls within the animation block.

https://developer.apple.com/documentation/uikit/uitableview/1614862-reloaddata https://developer.apple.com/documentation/uikit/uitableview/1614935-reloadrows

这篇关于tableView.reloadData和tableView.reloadRows之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆