【发布时间】:2016-12-11 02:27:48
【问题描述】:
我有一个 tableview,当其中一个行被点击时,我想去另一个 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)
}
【问题讨论】:
-
PlayVideoViewController 不是导航控制器的根目录,因此 pushViewController 方法不会运行。您需要通过转到情节提要添加导航控制器,选择 PlayVideoViewController,在顶部菜单中选择编辑器 -> 嵌入 -> 导航控制器。现在您的 PlayVideoViewController 将成为导航控制器的根,并且 pushViewController 应该可以正常工作。
-
@muazhud 我和你和 Bseaborn 说的一样。但它仍然无法正常工作
-
这是我对同一stackoverflow.com/a/56199240/1371853的回答
标签: ios swift pushviewcontroller