滑动删除不起作用
滑动删除功能在我的表视图中不起作用。我已经在导航栏中实现了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您是否实现了
tableView:editingStyleForRowAtIndexPath:
方法并让它返回UITableViewCellEditingStyleDelete
did you implement the
tableView:editingStyleForRowAtIndexPath:
method and have it returnUITableViewCellEditingStyleDelete
-(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 .让它工作的关键是实现:
并记住将其放在“UITableViewDataSource”而不是“UITableViewDelegate”中
The key to make it work is to implement:
And remember to put it inside "UITableViewDataSource" instead of "UITableViewDelegate"
您需要实施:
有了这三件事,您就可以开始了。 (我错过了 commitEditingStyle 并且它从未起作用。
You'll need to implement:
With these three things you should be good to go. (I missed off the commitEditingStyle and it never worked.
如果所有其他建议都没有帮助,请尝试检查代码中是否有平移手势识别器。如果您在某些底层视图中有类似的东西,它将不起作用。
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.
我在 tableView:editingStyleForRowAtIndexPath: 委托方法中执行以下操作:-
如果没有选择 indexPath,这应该返回编辑样式 none。由于某种原因,每当执行滑动操作时,就会执行这个特定的 if 条件。在评论上面的代码片段时,滑动删除操作运行良好。
感谢大家的帮助。
I was doing the following in the tableView:editingStyleForRowAtIndexPath: delegate method :-
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.
对于滑动删除功能,您必须实现
编辑:我没有很好地阅读这个问题。
我注意到,要在模拟器中进行滑动拖动,我必须在选择单元格时按下并暂停一秒钟,然后才能成功向右滑动。
For swipe-to-delete functionality, you have to implement
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.