【问题标题】:Left swipe for delete and edit,delete向左滑动删除和编辑,删除
【发布时间】:2011-04-12 21:20:55
【问题描述】:

我无法找到解决此问题的方法。是否可以使用左滑动以及使用编辑和删除来删除选项。

我在导航栏的左侧有编辑按钮。

self.navigationItem.leftBarButtonItem = self.editButtonItem;

和commitEditingStyle方法如下

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
//delete code here
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }   

}

使用此功能后,根本没有检测到向左滑动。删除的唯一方法似乎是进入编辑模式并从那里删除。 帮助将不胜感激。

我是新手,所以请放轻松:)

【问题讨论】:

  • 是的。除了您发布的内容中没有删除代码之外,似乎是什么问题。
  • 现在根本没有检测到向左滑动。我可以通过进入编辑模式并在那里删除来删除..但不使用左滑动:(
  • 顺便说一句:如果您不使用 UINavigationController,您应该只使用 NavigationBar 左侧的 EditButton。无论哪种方式,最好遵守指南并将 EditButton 放在导航栏的右侧
  • @amandir 我在右边有一个添加按钮。

标签: iphone objective-c xcode uitableview


【解决方案1】:

您的意思是在需要删除选项的单元格上滑动。

如果是这样你可以试试这个代码:

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

    return UITableViewCellEditingStyleDelete;

}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    //perform delete operation

}

【讨论】:

    【解决方案2】:

    确保您在下面实现了所有委托

    tableView:commitEditingStyle:forRowAtIndexPath:
    tableView:canEditRowAtIndexPath:
    tableView:editingStyleForRowAtIndexPath
    

    【讨论】:

    • 是的,我实现了,也连接了数据源和委托,不工作
    【解决方案3】:
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
        if (editingStyle == UITableViewCellEditingStyleDelete) {
    //delete code here
        }   
        else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
        }  
    

    一旦您在委托中编写了上述方法,您将能够使用滑动手势....在此方法中您将处理您想要执行的后续操作。

    谢谢.....

    【讨论】:

    • No.. 根本没有检测到左侧滑动。
    • UISwipeGestureRecognizer *tempGestureRecognizer = [[self.tableView gestureRecognizers] objectAtIndex:2]; tempGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight;
    猜你喜欢
    • 2011-09-02
    • 1970-01-01
    • 2010-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多