Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView重新排列单元格_Ios_Objective C_Xcode_Uitableview - Fatal编程技术网

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的答案。