ios - pushViewController 不做任何 Action

标签 ios swift pushviewcontroller

我有一个表格 View ,我想在点击其中一行时转到另一个 vc。我的 didSelectRowAtIndexPath 函数如下所示。打印命令有效并显示右键单击的行。但是当我使用 self.navigationController?.pushViewController 时,它不会使用 playVideo storyBoardId 转到 vc。将其更改为 presentViewController 后,它就可以工作了。我的推送不起作用的代码有什么问题?

谢谢

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    print("clicked " + String(indexPath.row) )
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("playVideo") as! PlayVideoViewController

    vc.id = self.video[indexPath.row].id

    // Present View as Modal
    //presentViewController(vc as UIViewController, animated: true, completion: nil)
    // Push View
    //self.navigationController?.pushViewController(vc, animated: true)
}

最佳答案

  • 这是因为您当前所在的 View Controller 可能没有导航 Controller 。
  • 没有 UINavigationController 就无法推送 View Controller 。
  • 如果您的要求是推送 View Controller ,请执行以下步骤。

    1. 为当前 View Controller 嵌入一个导航 Controller 。(打开 Storyboard -> 选择你的 View Controller -> 选择“编辑器” -> “嵌入” -> UINavigationController)
    2. 现在你的代码

    self.navigationController?.pushViewController(vc, animated: true)

将正常工作。

关于ios - pushViewController 不做任何 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38776247/

相关文章:

ios - 在不同部分的索引处选择行

iOS 应用滞后....图像可能是罪魁祸首吗?

swift - setScreenname() 仅在 logEvent() 之后触发

iPhone - 获取插入我的 Controller

ios - 如何制作pushViewController : work in the following case?

ios - 在字符串 : Swift 中的特定字符之后插入字符

ios - 没有导航 Controller 的通知操作打开 View

ios - swift 函数返回对象或 nil

ios - 为什么在调用scrollToRow时重新加载数据会导致崩溃?

ios - hidebottombarwhenpush 无法将 tabbarcontroller Storyboard移动到另一个 Storyboard