【问题标题】:UITableView Swipe to delete not working properly on iOS8UITableView 滑动删除在 iOS8 上无法正常工作
【发布时间】:2014-12-21 22:56:46
【问题描述】:

我有一个视图控制器,在 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 上滑动手势不能正常工作。

我使用 iPhone 6 在 iOS8 上对此进行了测试,要激活滑动,我需要从边缘表格单元格滑动 20 次或更多次,有时甚至根本无法获得滑动删除按钮。

我检查并尝试了堆栈溢出的大多数解决方案。任何帮助或建议将不胜感激。

情节提要中的层次结构如下图所示。

【问题讨论】:

  • 滑动手势是使用滚动视图实现的。您的单元格中是否有任何可能与您的滑动手势发生冲突的东西?例如。另一个滚动视图?
  • 没有滚动视图或手势识别器和奇怪的东西滑动在 ios7 上完美运行。
  • 我的情况也是这样。你能帮忙吗?出了什么问题?

标签: objective-c iphone uitableview ios8 swipe


【解决方案1】:

同样的问题,滑动在模拟器和设备上的工作时间只有大约 20%。在我的例子中,它是由 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,请确保没有设置与滑动删除平移手势发生冲突的其他平移手势。

【讨论】:

    【解决方案2】:

    有时,除了 panGesture 之外,还有其他手势识别器。如果您想保留平移手势或其他识别器,并且仍然允许滑动删除,我已经在可见视图控制器中使用以下类别完成了此操作:

    @interface UIView (CellSwipeAdditions)
        - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
    @end
    
    @implementation UIView (CellSwipeAdditions)
        - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
            return YES;
        }
    @end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-14
      • 1970-01-01
      • 1970-01-01
      • 2014-04-21
      相关资源
      最近更新 更多