iOS開發學習之#表視圖#(3)移動行

繼續上篇接下來介紹移動行:移動行我們用

- (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];
}





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章