【问题标题】:Enter edit mode with single row/cell使用单行/单元格进入编辑模式
【发布时间】:2013-03-18 03:29:22
【问题描述】:

我有一个来自这个例子的自定义滑动识别类: How to detect a swipe-to-delete gesture in a customized UITableviewCell?

    - (void)cellSwiped:(UIGestureRecognizer *)gestureRecognizer {
    if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
        UITableViewCell *cell = (UITableViewCell *)gestureRecognizer.view;
        NSIndexPath* indexPath = [self.tableView indexPathForCell:cell];
    }
}

现在我想在 indexPath 中选择那一行并为其启用编辑模式,有人可以告诉我如何完成吗?

【问题讨论】:

    标签: iphone objective-c editmode


    【解决方案1】:

    在某处缓存您想要的行,并在您的- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 实现中只为您希望可编辑的行返回YES。然后发送[tableView setEditing:YES animated:YES];进入编辑模式。

    【讨论】:

    • 我明白你想说什么,但我对 iOS 编程还很陌生,我不完全明白必须做什么。我做了这样的事情,它似乎不起作用。 if ([notifTable cellForRowAtIndexPath:indexPath]) { [[notifTable cellForRowAtIndexPath:indexPath]setEditing:YES 动画:YES];返回是;
    【解决方案2】:

    你可以在你的类中有一个变量是 NSIndexPath *index 然后有

    -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
        return indexPath == self.index;
    }
    

    并将索引设置为您希望能够编辑的任何单元格,然后在您想要编辑该单元格时调用tableView setEditing:YES animated:YES/NO

    【讨论】:

      【解决方案3】:

      这样试试,

      在你的tableViewdidSelectRowAtIndex委托方法中调用editingStyleForRowAtIndexPath方法,

      - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       [yourTableView.delegate tableView:tableView editingStyleForRowAtIndexPath:indexPath];
      }
      

      editingStyleForRowAtIndexPath方法中,

      - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
      
      
        return UITableViewCellEditingStyleDelete;
      
        }
      
      
      - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
      
      
      
      }
      

      【讨论】:

        猜你喜欢
        • 2014-12-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-20
        • 2015-10-03
        • 1970-01-01
        相关资源
        最近更新 更多