2011-04-12 146 views
0

我无法找到解决方法。是否可以使用左滑动来删除选项,还可以使用编辑和删除。左滑动删除和编辑,删除

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

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. 
    } 

}

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

我是一个新手,所以请去容易与我:)

+0

是。除了您发布的内容中没有删除代码之外,似乎是什么问题。 – Jordan 2011-04-12 08:21:03

+0

现在左侧刷卡根本没有被检测到。我可以通过去编辑模式和删除那里删除..但不使用左滑动:( – Neelesh 2011-04-12 08:23:41

+0

顺便说一句:如果你不使用UINavigationController,你应该只使用NavigationBar的左侧的EditButton。无论哪种方式,它是总是更好地坚持准则,并将EditButton放置在导航栏的右侧 – Amandir 2011-04-12 08:26:48

回答

3

你的意思是对细胞刷你需要删除选项。

如果是的话,你可以试试这个代码:

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

    return UITableViewCellEditingStyleDelete; 

} 

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

    //perform delete operation 

} 
0
- (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. 
    } 

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

感谢.....

+0

没有..根本没有检测到左侧滑动 – Neelesh 2011-04-12 08:39:02

+1

UISwipeGestureRecognizer * tempGestureRecognizer = [self.tableView gestureRecognizers] objectAtIndex:2]; tempGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight; – Ravin 2011-04-12 09:06:18

1

确保以下

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

你所有的代表实施:

+0

是的,我实现了,也连接数据源和委托,不工作 – 2014-07-03 08:03:46