为什么 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/