gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 05:38:47 25 4
gpt4 key购买 nike

我正在尝试在我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com