self?.performSegue 不显示导航栏

col*_*ole 5 uinavigationbar storyboard ios swift

self?.performSegue(withIdentifier: "myview", sender: nil)
Run Code Online (Sandbox Code Playgroud)

即使我在故事板中使用推送,上面的代码也不显示导航栏。下面的代码显示了一个错误,即使存在具有正确名称的 segue

self?.navigationController?.performSegue(withIdentifier: "myview", sender: nil)
Run Code Online (Sandbox Code Playgroud)

错误

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“Receiver () 没有标识符为“myview”的 segue”

Dáv*_*tor 3

self?.navigationController?.performSegue(withIdentifier: "myview", sender: nil) Segue 附加到UIViewController子类实例而不是实例UINavigationController,因此您不能在后者上调用它。

如果执行segue后没有导航栏,则必须确保将视图控制器正确嵌入导航控制器中,或者如果手动添加导航栏,请确保将其添加到其他视图控制器中,如下所示好在viewWillAppear方法中。