滑动删除不起作用

发布于 2024-09-19 21:10:23 字数 670 浏览 6 评论 0原文

滑动删除功能在我的表视图中不起作用。我已经在导航栏中实现了 commitEditingStyle 委托和编辑按钮。因此,当用户单击编辑按钮时,删除和添加按钮会相应显示。但是,在滑动时,删除按钮不会出现,并且似乎它无法将滑动识别为对 setEditing 方法的调用。

然后,我实现了 willBeginEditingRowAtIndexPath 和 didEndEditingRwoAtIndexPath 委托,如下所示:

-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath

{
 NSLog(@"WILL BEGIN EDITING");

 [self.tableView setEditing:YES animated:YES];

}


-(void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath

{

[self.tableView setEditing:NO animated:YES];

}

但是,这也没有任何效果。可能的问题是什么?我在 IB 中为表格视图启用了多点触控,并且每个单元格都有一个 DetailDisclosureButton 附件。

The swipe to delete functionality is not working in my table view. I have implemented the commitEditingStyle delegate and the Edit button in the navigation bar. Hence when the user clicks the edit button, the delete and add buttons show up appropriately. However, on swiping, the delete button does not appear and it seems like it doesn't recognise the swipe as a call for the setEditing method.

I then implemented willBeginEditingRowAtIndexPath and didEndEditingRwoAtIndexPath delegates as follows:

-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath

{
 NSLog(@"WILL BEGIN EDITING");

 [self.tableView setEditing:YES animated:YES];

}


-(void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath

{

[self.tableView setEditing:NO animated:YES];

}

However this does not have any effect either. What could be the possible issue? I have enabled multi-touch for the table view in the IB and each cell has an DetailDisclosureButton accessory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

怕倦 2024-09-26 21:10:27

您是否实现了 tableView:editingStyleForRowAtIndexPath: 方法并让它返回 UITableViewCellEditingStyleDelete

did you implement the tableView:editingStyleForRowAtIndexPath: method and have it return UITableViewCellEditingStyleDelete

一念一轮回 2024-09-26 21:10:27

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 委托方法还需要实现才能工作滑动功能。

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath delegate method also need to implement to work swipe functionality .

小瓶盖 2024-09-26 21:10:26

让它工作的关键是实现:

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

并记住将其放在“UITableViewDataSource”而不是“UITableViewDelegate”中

The key to make it work is to implement:

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

And remember to put it inside "UITableViewDataSource" instead of "UITableViewDelegate"

时常饿 2024-09-26 21:10:25

您需要实施:

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


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;

有了这三件事,您就可以开始了。 (我错过了 commitEditingStyle 并且它从未起作用。

You'll need to implement:

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


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;

With these three things you should be good to go. (I missed off the commitEditingStyle and it never worked.

尐籹人 2024-09-26 21:10:25

如果所有其他建议都没有帮助,请尝试检查代码中是否有平移手势识别器。如果您在某些底层视图中有类似的东西,它将不起作用。

If all other advices doesn't help try to check if you have pan gesture recognizer in your code. It will not work if you have things like this in some underlaying view.

深爱不及久伴 2024-09-26 21:10:25

我在 tableView:editingStyleForRowAtIndexPath: 委托方法中执行以下操作:-

if (self.editing == NO || !indexPath)
{   
    return UITableViewCellEditingStyleNone;
}

如果没有选择 indexPath,这应该返回编辑样式 none。由于某种原因,每当执行滑动操作时,就会执行这个特定的 if 条件。在评论上面的代码片段时,滑动删除操作运行良好。

感谢大家的帮助。

I was doing the following in the tableView:editingStyleForRowAtIndexPath: delegate method :-

if (self.editing == NO || !indexPath)
{   
    return UITableViewCellEditingStyleNone;
}

This was supposed to return editing style none if no indexPath was selected. For some reason whenever a swipe action was performed, this particular if condition was getting executed. On commenting the above code snippet, the swipe to delete action worked fine.

Thanks all for your help.

剑心龙吟 2024-09-26 21:10:24

对于滑动删除功能,您必须实现

 -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
        ; // Delete.
}

编辑:我没有很好地阅读这个问题。

我注意到,要在模拟器中进行滑动拖动,我必须在选择单元格时按下并暂停一秒钟,然后才能成功向右滑动。

For swipe-to-delete functionality, you have to implement

 -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
        ; // Delete.
}

EDIT: I didn't read the question well enough.

I have noticed that to do a swipe drag in the simulator I have to press and pause for a second while it selects the cell, and only then can I swipe right successfully.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文