2016-08-23 44 views
1

我希望我的swift应用程序在按下UITableViewRowAction“Edit”时打开一个UIViewController(称为“SecondViewController”)。不过,我下面的代码并没有做任何事情;当我按下“编辑”操作时,绝对没有任何反应。当按下“编辑”UITableViewRowAction时,无法切换到另一个UIViewController

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 

//Edit action 
let editAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Edit") { (editAction, indexPath) -> Void in 

    let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("secondViewController") as! SecondViewController 
    self.navigationController?.pushViewController(secondViewController, animated: true) 

} 

return [editAction] 

} 

这怎么能解决?这甚至有可能吗?如果需要更多信息,请发表评论。

+0

我认为导航控制器是零。请在故事板 –

+0

Ha中添加导航控制器,这非常简单。不知道我需要有一个uinavigationcontroller这个工作。谢谢。把它作为答案(只是复制粘贴),以便我可以将其标记为正确。 – Bossvanlindt

+0

我已经回答。请检查 –

回答

1

我认为navigationController是零。您可以通过storyboard添加navigationController或者以编程方式创建它并使ViewController包含tableView作为rootViewController。这应该工作

+0

Noice的工作噪音。做得好。 – Bossvanlindt

相关问题