我有一个视图控制器,在uiview中有一个uitableview。委托和数据源已正确嵌入,并且一切正常。
我正在使用commitEditingStyle和canEditRowAtIndexPathMethods委托方法来滑动删除功能。
方法的用法如下。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSDictionary *dataElement = [cartArray objectAtIndex:indexPath.row];
NSString *productId = [dataElement objectForKey:@"id"];
NSString *productSizeId = [dataElement objectForKey:@"beden_id"];
[self deleteTableRowWithId:productId sizeId:productSizeId];
}
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
滑动手势和委托方法在没有在模拟器和设备上都经过测试的iOS7上正常运行,没有任何问题,但是在iOS8上,滑动手势无法正常工作。
我在iOS8上使用iPhone 6进行了测试,并且要激活滑动,我需要从边缘表单元中滑动20次或更多次,有时甚至根本无法获得滑动删除按钮。
我检查并尝试了大多数有关堆栈溢出的解决方案。任何帮助或建议将不胜感激。
故事板上的层次结构如下图所示。
同样的问题,在模拟器和设备上,滑动仅能在20%的时间内起作用。在我的情况下,这是由ECSlidingViewController(一种流行的滑动菜单实现)引起的,ECSlidingViewController设置了水平平移手势以打开菜单。viewDidAppear:
您需要在要滑动删除操作正常工作的控制器中禁用此手势:
#import "ECSlidingViewController.h"
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// Disable sliding menu pan gesture so it doesn't conflict with table view swipe-to-delete
self.slidingViewController.panGesture.enabled = NO;
}
如果希望其他控制器能够使用它,请确保重新启用摇动手势:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// Re-enable sliding menu pan gesture so other controllers can use it
self.slidingViewController.panGesture.enabled = YES;
}
有关此问题的更多信息,请参见此请求请求:https : //github.com/ECSlidingViewController/ECSlidingViewController/pull/70
长话短说,无论您是否使用ECSlidingViewController,请确保没有设置任何其他与轻扫到删除的平移手势相冲突的平移手势。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句