【问题标题】:Is there anyway to simulate a cell swipe so the cell swipes when the cell is tapped?有没有办法模拟单元格滑动,以便在点击单元格时滑动单元格?
【发布时间】:2015-01-06 15:15:23
【问题描述】:

我一直在尝试为此寻找解决方案,想知道是否有任何方法可以模拟单元格滑动,因此当您点击单元格时,它会滑动以显示其选项(即删除选项)。我实际上正在使用 MSSwipeTable 单元格 (https://github.com/MortimerGoro/MGSwipeTableCell),我喜欢动画效果,但我希望它能够用于点击不滑动的单元格。有什么想法吗?

谢谢

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    在 Swift 中,您可以执行以下操作:

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
          let cell = self.tableView.cellForRowAtIndexPath(indexPath) as! MGSwipeTableCell
          cell.showSwipe(MGSwipeDirection.RightToLeft, animated: true)
    }
    

    【讨论】:

      【解决方案2】:

      MGSwipeTableCell 中有一个方法:-(void) showSwipe: (MGSwipeDirection) direction animated: (BOOL) animated;

      您只需在 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 方法中调用它。

      https://github.com/MortimerGoro/MGSwipeTableCell/blob/master/MGSwipeTableCell/MGSwipeTableCell.h#L153

      【讨论】:

      • 太棒了!谢谢,我去看看结果发回
      • 我必须在公共界面中声明单元格吗?不确定如何访问 (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 中的单元格对象,因为它使用 NSIndexPath。
      • 成功了!使用:MGSwipeTableCell * cell2 = [self.tableView cellForRowAtIndexPath:indexPath];然后:[cell2 showSwipe:MGSwipeDirectionRightToLeft 动画:YES];效果很好!谢谢!
      猜你喜欢
      • 2016-02-19
      • 2021-09-18
      • 2014-03-21
      • 1970-01-01
      • 2014-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多