在UITabBarController中,可以通过以下步骤将UINavigationController推入到UITabBarController中:

  1. 创建一个UINavigationController对象,并将需要推入的UIViewController对象设置为UINavigationController的根视图控制器。
let navigationController = UINavigationController(rootViewController: viewController)
  1. 将UINavigationController对象添加到UITabBarController中的viewControllers数组中。
tabBarController.viewControllers?.append(navigationController)
  1. 如果需要,可以设置UINavigationController的标题和图标。
navigationController.tabBarItem.title = "Title"
navigationController.tabBarItem.image = UIImage(named: "ImageName")

完整的代码示例:

let viewController = UIViewController()
viewController.view.backgroundColor = UIColor.white

let navigationController = UINavigationController(rootViewController: viewController)
navigationController.tabBarItem.title = "Title"
navigationController.tabBarItem.image = UIImage(named: "ImageName")

tabBarController.viewControllers?.append(navigationController)

注意:需要将上述代码放置在UITabBarController的视图加载完毕后执行,例如在viewDidLoad方法中执行

oc中如何在UITabBarController 中push一个UINavigationController

原文地址: https://www.cveoy.top/t/topic/hBwA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录