在UIViewController中以编程方式添加UINavigationController,可以通过以下步骤实现:
import UIKit
class YourViewController: UIViewController {
// Your view controller code
}
import UIKit
class YourViewController: UIViewController {
// Your view controller code
func addNavigationController() {
let navigationController = UINavigationController(rootViewController: self)
// Customize the navigation controller if needed
}
}
import UIKit
class YourViewController: UIViewController {
// Your view controller code
func addNavigationController() {
let navigationController = UINavigationController(rootViewController: self)
// Customize the navigation controller if needed
// Add the navigation controller's view to the current view controller's view
addChild(navigationController)
view.addSubview(navigationController.view)
navigationController.didMove(toParent: self)
}
}
import UIKit
class YourViewController: UIViewController {
// Your view controller code
override func viewDidLoad() {
super.viewDidLoad()
addNavigationController()
}
func addNavigationController() {
let navigationController = UINavigationController(rootViewController: self)
// Customize the navigation controller if needed
// Add the navigation controller's view to the current view controller's view
addChild(navigationController)
view.addSubview(navigationController.view)
navigationController.didMove(toParent: self)
}
}
现在,当您运行应用程序时,您的UIViewController将以编程方式包含一个UINavigationController。
领取专属 10元无门槛券
手把手带您无忧上云