ios - 为什么tableView是:canMoveRowAtIndexPath: in the UITableViewDataSource protocol?

标签 ios uitableview cocoa-touch model-view-controller delegates

为什么 tableView:canMoveRowAtIndexPath:UITableViewDataSource协议(protocol)而不是 UITableViewDelegate协议(protocol)?

类似的方法(例如 tableView:canFocusRowAtIndexPath:)在 Delegate 协议(protocol)中。我不认为这是一个错误,所以谁能解释为什么这种方法是数据源的一部分而不是委托(delegate)的一部分?

对于哪些方法属于数据源协议(protocol)以及哪些方法属于委托(delegate)协议(protocol)的一般解释也很受欢迎。

最佳答案

委托(delegate)方法通常与表格 View 的外观有关。

数据源方法通常与 TableView 的内容有关。通常情况下,显示内容的顺序是固定的。假设表格 View 显示公交线路上的停靠站,或一本书的章节标题。您不能让用户重新排序:内容本身 不支持它。

请注意,委托(delegate)和数据源实际上都参与了行是否可以移动的决定。数据源获取您命名的方法,但委托(delegate)被询问 tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:同时。

关于ios - 为什么tableView是:canMoveRowAtIndexPath: in the UITableViewDataSource protocol?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35955383/

相关文章:

ios - 在 tableview 单元格内单击更改按钮

ios - 如何将segmentedControl和UISearchController作为UITableViewController header ? (以编程方式)

ios - 尝试查看 UITableViewRowCell 中的两个 UITextFields 是否都包含 iOS 中的文本

ios - 在 UIWebview 中获取当前 URL 但它没有响应

ios - 在 tableView :editActionsForRowAt: 中处理图像

ios - iOS 中 ARKit2.0 扫描和检测 3D 物体有哪些限制?

android - android sherlock actionbar 与 iOS 中的 UINavigationBar 相同吗?

ios - 将 2 个图像从 JSON 解析为 UITableViewCell

ios - 自动展开 UITableView - NSRangeException

iphone - 让对象在从 super View 中删除后发送自己的委托(delegate)消息