如何从UITableView滑动触发segue到swift中的Edit

时间:2015-11-04 09:36:56

标签: ios swift uitableview swipe

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

2 个答案:

答案 0 :(得分:0)

请尝试以下代码:

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

并创建滑动操作:

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
}

答案 1 :(得分:0)

要在代码中预先形成segue,您可以使用代码行:self.preformSegueWithIdentifyer("idenyidfyer",nil。要在视图视图控制器中创建segue,请控制从视图控制器单击并拖动到所需的视图控制器。单击segue并将标识符更改为您想要的内容。