显示带有导航栏的 XIB viewController (Swift)

Present XIB viewController with navigation bar (Swift)

这是我正在使用的代码

var xibvc = TestXibViewController()
var navb = UINavigationController(rootViewController: xibvc)
self.presentViewController(xibvc,animated: true, completion: nil)

我想为 xibviewcontroller 提供一个导航栏,它给了我这个错误

reason: 'Application tried to present modally an active controller

尽管如此,如果我尝试 pushViewController

它工作正常

您的代码毫无意义。 navb 有什么用?你创建它,然后你永远不会使用它。

你可能想说:

self.presentViewController(navb,animated: true, completion: nil)
                           ^^^^