任何人都可以为我提供表格 View 拖放功能的示例吗?
最佳答案
当您创建 UITableView Controller 的子类时,取消注释以下方法(或者如果您在自定义类中实现 UITableView
delegate
和 dataSource
协议(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/