【问题标题】:Swipe left to delete cell does not work properly in ios 8 but works in ios 7向左滑动删除单元格在 ios 8 中无法正常工作,但在 ios 7 中有效
【发布时间】:2014-11-26 17:18:03
【问题描述】:

删除表格单元格的滑动无法正常工作。我必须非常快速地多次滑动才能使其正常工作。下面的代码在 ios 7 中运行。有人可以告诉我需要做什么才能让它在 ios 8 中顺利运行吗?

@implementation SimpleTableCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)willTransitionToState:(UITableViewCellStateMask)state{

    [super willTransitionToState:state];


    if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
        for (UIView *subview in self.subviews) {
            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
                UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
                [deleteBtn setImage:[UIImage imageNamed:@"deleteButton.png"]];
                [[subview.subviews objectAtIndex:0] addSubview:deleteBtn];
            }
        }
    }
}
@end

【问题讨论】:

    标签: ios objective-c ios7 ios8


    【解决方案1】:

    我遇到了完全相同的问题。几个小时后,我终于发现问题出在包含滑动手势识别器的导航控制器上。

    原生评论编辑功能使用 Swipe GestureRecognizer,所以如果您有任何手势识别器,请不要忘记添加此行以允许同时进行手势识别!

    - (BOOL)gestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UISwipeGestureRecognizer *)otherGestureRecognizer { return YES; }
    

    我真的希望它会有所帮助,因为它让我发疯......

    【讨论】:

      【解决方案2】:

      这应该非常简单(在 iOS 8 中对我来说效果很好......)

      你只需要确保你的 UITableView 有这个:

      -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
      {
          // YES - we do want to enable "swipe to delete" on this row. 
          return YES;
      }
      

      ...还有这个...

      -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
      {
          //  Add some code to delete your row...
      }
      

      你的代码中有这两部分吗?

      【讨论】:

        猜你喜欢
        • 2014-11-28
        • 2015-01-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多