ios - storyboard页面跳转到代码页面,UINavigationController在代码页面没有成功显示
伊谢尔伦
伊谢尔伦 2017-04-18 09:54:54
0
2
489

问题

  1. storyboard跳转到代码界面,UINavigationController在storyboard界面显示,代码界面不显示

代码

我是在AppDelegate里增加UINavigationController

//AppDelegate.swift
let storyboard = UIStoryboard(name:"Main",bundle:nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "LoginViewController")
//let viewController = LoginViewController()
let nav = UINavigationController(rootViewController: viewController)
self.window?.rootViewController = viewController
self.window?.addSubview(nav.view)
self.window?.makeKeyAndVisible()

//统一导航条样式
let textAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize: 19.0), NSForegroundColorAttributeName: UIColor.white]
UINavigationBar.appearance().titleTextAttributes = textAttributes
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().barTintColor = UIColor.red

在storyboard界面通过该方式跳转

//LoginViewController.swift
let chatListView = SingleChatListViewController()
self.present(chatListView, animated: true, completion: nil)

结果

这个首页是正常的

这个就不对了

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全員に返信(2)
PHPzhong

self.present(chatListView, animated: true, completion: nil)

self.navigationController?.pushViewController(chatListView , animated: true)
に置き換えればOKです
nav で表示されるページと同じロジックでない場合は present を使用して表示します。この方法を使用できます

いいねを押す +0
刘奇

Swift を使用したことがありませんが、間違った API を使用しているようです

リーリー

Self.navigationViewController はプッシュでジャンプを使用します。現在は別のジャンプ メソッドです

いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート