【发布时间】:2011-11-10 13:13:42
【问题描述】:
谁能给我一个表格视图拖放功能的示例?
【问题讨论】:
标签: ios uitableview
谁能给我一个表格视图拖放功能的示例?
【问题讨论】:
标签: ios uitableview
当您创建 UITableView 控制器的子类时,取消注释以下方法(或者如果您在自定义类中实现 UITableView delegate 和 dataSource 协议,则只需添加它们):
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
// update your model
}
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
现在你只需要一个编辑按钮来启动编辑模式(你可以把它放在 viewDidLoad 中):
self.navigationItem.rightBarButtonItem = self.editButtonItem;
在 tableView:moveRowAtIndexPath:toIndexPath: 方法中,您应该通过重新排列数组或保存数据的任何内容来更新模型。
【讨论】: