繼續上篇接下來介紹移動行:移動行我們用
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
(UITableView *)tableView用來指定表視圖,(NSIndexPath *)sourceIndexPath用來指定要移動行的索引路徑,(NSIndexPath *)destinationIndexPath用來指定行移動到目標位置的索引路徑
核心代碼:
<pre name="code" class="objc">//移動行
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
NSInteger fromRow = [sourceIndexPath row];
NSInteger toRow = [destinationIndexPath row];
id object = [a objectAtIndex:fromRow];
[a removeObjectAtIndex:fromRow];
[a insertObject:object atIndex:toRow];
}