【问题标题】:Unable to switch to another UIViewController when “Edit” UITableViewRowAction is pressed按下“编辑”UITableViewRowAction 时无法切换到另一个 UIViewController
【发布时间】:2016-08-23 17:55:58
【问题描述】:

我希望我的 swift 应用程序在按下 UITableViewRowAction“编辑”时打开一个 UIViewController(称为“SecondViewController”)。但是,我下面的代码什么也没做;当我按下“编辑”操作时,绝对没有任何反应。

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]

}

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

【问题讨论】:

  • 我认为导航控制器是零。请在情节提要中添加导航控制器
  • 哈,这很简单。不知道我需要有一个 uinavigationcontroller 才能工作。谢谢。将其作为答案(只需复制粘贴),以便我将其标记为正确。
  • 我已经回答了。请检查

标签: ios uiviewcontroller swift2 uitableviewrowaction


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2015-12-04
    相关资源
    最近更新 更多