【问题标题】:drag and drop in uitableview在uitableview中拖放
【发布时间】:2011-02-24 14:41:06
【问题描述】:

我目前正在开发一个应用程序,其中以表格视图的形式向用户显示列表。当用户选择特定行时,他/她可以将其拖动到另一行。发生这种情况时,会显示一条警报,提供一些特定信息。您知道如何做到这一点吗?

What I am doing is that I am using gesture recognizers.When a particular row is selected, an image of the selected row is made which then is dragged to the specific table view cell.I am able to move the image but my问题是,如果我不将 imageView 放在 UIView 下,拖动的东西就不会发生.....

我的拖拽代码是基于苹果的touches sample code .

更新:

经过一段时间的尝试,我几乎可以实现这一点。不过我仍然有一个疑问..一旦点击它,我就会创建一个单元格的图像。然后 UIPanGestureRecognizer 已添加到它转而制作的那个 imageView它的移动可能。唯一的问题是我怎么知道图像被丢弃在哪个单元格上?

【问题讨论】:

    标签: iphone uitableview drag-and-drop


    【解决方案1】:

    你应该实现:

    - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
    

    这将返回 YES,并且还实现:

    - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
     //do whatever u want after row has been moved
    }
    

    然后从tableView调用这个函数:

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated
    

    进入编辑模式。

    【讨论】:

    • @Ratinho .....我不必显示单元格的重新排序....而是我必须在单元格上显示拖放操作。当我实施您建议的方法时,单元格我必须放弃的东西上升了,看起来像是重新排序....
    • 哦,对不起,我没听懂你的意思。
    • 你实现过这个功能吗?
    【解决方案2】:

    这是一个应用程序示例,它使用 UITableView 的委托和数据源的本机方法在 UITableView 中拖放单元格。 https://github.com/coderDove/UITableView-Drag-n-Drop

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      • 1970-01-01
      • 2015-11-22
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多