Ios UITableView重新排列单元格
我试图从苹果公司的角度实现这个方法Ios UITableView重新排列单元格,ios,objective-c,xcode,uitableview,Ios,Objective C,Xcode,Uitableview,我试图从苹果公司的角度实现这个方法 - (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath 但我的代码在实现此方法之前不起作用: - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)to
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
但我的代码在实现此方法之前不起作用:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
我完全不知道为什么它不起作用,为什么它现在起作用
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath
toIndexPath:(NSIndexPath *)newIndexPath
用于UITableView
子类
- (void)tableView:(UITableView *)tableView
moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath
用于数据源。显然,您没有使用子类,而是实现委托/数据源方法。不过,这是有道理的。如果您是一个子类,则只能有一个可能的表视图。如果您是一个数据源,您可以拥有任意数量的数据(您可以是100个表视图的数据源)。这样,您需要知道您正在处理的是哪个表视图,因此需要额外的参数
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
这是将表视图中特定位置的行移动到另一位置的数据源方法。当用户按下reorder控件时,将调用此方法,您必须在其中重新排列数据,以便基于fromIndexpath和toIndexPath处重新排序的数据重新绘制表视图。有必要更改基础数据的顺序,可能是
NSMutableArray
。见下面@nkongara的答案。