2012-01-30 71 views
0

我有一个iPad应用程序与UITableView,我想让用户通过拖动单元格并将其移动到另一个单元格之前或之后重新排序表项目,我该怎么做?UITableView与拖动

坦克

回答

2

在数据shource实现moveRowAtIndexPath:toIndexPath:的方法更新结束模型的拖动操作。执行tableView:canMoveRowAtIndexPath:以返回YES用户应该能够移动的行。 Here是关于这个主题的简短教程。

2

您需要实现在您的视图控制器来使用这些数据源的方法:

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return YES; 
} 

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath 
{ 
    //update your model to reflect the fact that the specified rows indexes have been swapped 
}