ios - UITableView 拖放功能

标签 ios uitableview

任何人都可以为我提供表格 View 拖放功能的示例吗?

最佳答案

当您创建 UITableView Controller 的子类时,取消注释以下方法(或者如果您在自定义类中实现 UITableView delegatedataSource 协议(protocol),则只需添加它们):

// 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:方法,您应该通过重新排列数组或保存数据的任何内容来更新模型。

关于ios - UITableView 拖放功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7307140/

相关文章:

ios - 容器 View Controller 中的 tableviewcontroller : programatically selecting uitableviewcell, 突出显示闪烁

ios - UICollectionView reloadData 有效,但 reloadItemsAtindexPaths 无效

ios - 如何用字符串绘制 2 个带 x 轴的折线图

ios - 无法通过 UIAlert 中的闭包关闭 View Controller

ios - 如何从 CustomCell 重置 tableview 中的所有开关

ios - 使用键盘使 UITableview 的底部向上移动

ios - 自动布局不适用于 iOS7 和 Xcode 6

ios - Cocoapods:pod lint 有效,但由于缺少 versioned_frameworks,pod repo push 无法验证

iOS 在一个数组中搜索,通过另一个数组的索引匹配

iOS PullToRefreshView,添加didFinishRefreshing方法