【问题标题】:TableView drag & drop functionalityTableView 拖放功能
【发布时间】:2011-11-10 13:13:42
【问题描述】:

谁能给我一个表格视图拖放功能的示例?

【问题讨论】:

标签: ios uitableview


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    你需要重新排列吗? .如果是这样检查this 或者如果你需要拖放检查this

    【讨论】:

      猜你喜欢
      • 2012-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 2019-11-19
      • 1970-01-01
      相关资源
      最近更新 更多