ios - 如何从 UITableView 滑动触发 segue 以快速编辑

标签 ios swift uitableview swipe

我正在尝试在我的 UITableView 中包含滑动功能,我想从那里执行一个 segue。例如,当单元格向左滑动时,它会显示一个 Edit 按钮,当按下这个编辑按钮时,它会打开一个新的 ViewController.UI

最佳答案

试试下面的代码:

let cSelector : Selector = “swipeAction”

let rightSwipe = UISwipeGestureRecognizer(target: self, action: cSelector)
rightSwipe.direction = UISwipeGestureRecognizerDirection.Right
mainTableView.addGestureRecognizer(rightSwipe) // Or you can add it to cell

并创建滑动 Action :

func swipeAction()
{
    // TODO 
    self.performSegueWithIdentifier("segueId", sender: nil)
}

或者您可以在滑动单元格时直接调用 segue(如果您实现了像 canEditCellForRow 这样的内置滑动)

并实现prepareForSegue方法

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.

    let controller = segue.destinationViewController as YourDestViewController
    controller.someData = // Pass some object if you need
}

关于ios - 如何从 UITableView 滑动触发 segue 以快速编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33518280/

相关文章:

ios - 如何使用 ios-charts 创建游标

ios - 在 ARKit 中获取一个点的绝对位置

swift - 无法将数据从 UIPickerView 传递到 CustomTableViewCell

iphone - UITableView 中 Plist 中的数据排序不正确

ios - Swift UICollectionView 在点击时更新单元格标签而不是实时更新

iphone - 如何删除节的最后一行?

ios - 为 UIViewController 中的 UIView 创建 Controller

ios - Xcode 构建问题

iOS View 对象属性与操作方法

ios - 如何从扩展中的函数创建 UIActivityIndi​​cator 计算属性