在运行时重新排列表格视图中的单元格

Posted

技术标签:

【中文标题】在运行时重新排列表格视图中的单元格【英文标题】:Rearrange cells in tableview during runtime 【发布时间】:2010-02-08 01:15:15 【问题描述】:

有人可以为我指出正确的方向吗?如何让细胞能够在UITableView 中移动?

当我单击并按住然后拖动到第二个单元格下方时,它不会移动。它只是拖动所有单元格并再次向上伸展。

我希望能够移动单元格,这样我基本上可以在运行时重新排列单元格。谁能帮帮我。

【问题讨论】:

【参考方案1】:

这是UITableView 为您提供的功能。

检查TableView Programming Guide 中的Managing the Reordering of Rows 部分。

【讨论】:

【参考方案2】:

您只能在编辑模式下重新排列表格视图单元格。

在你的程序中寻找这行代码:

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem; 

如果你还没有接触过它应该被评论。

干杯!

凯尔

【讨论】:

【参考方案3】:

试试这个

- (void) tableView:(UITableView *)tableView
moveRowAtIndexPath:(NSIndexPath *)fromIndexPath 
       toIndexPath:(NSIndexPath *)toIndexPath 

【讨论】:

以上是关于在运行时重新排列表格视图中的单元格的主要内容,如果未能解决你的问题,请参考以下文章