gpt4 book ai didi

ios - 以编程方式在 UITabBarController 和 UINavigationController 中呈现 View

转载 作者:行者123 更新时间:2023-11-28 13:52:12 25 4
gpt4 key购买 nike

我们正在开发一个 iOS 应用程序,它有一个 RootVC,其中以编程方式放置 4 个 TAB,每个 Tab 都有一个单独的 ViewController。负责搜索的选项卡之一。当用户点击此特定 ViewController 上的搜索按钮时,我们希望在另一个具有 TabBarViewController 中显示搜索结果位于底部,NavigationController 位于顶部,带有“后退”按钮。我怎样才能做到这一点?我尝试使用 self.navigationController?.present 进行推送,但它们都不起作用。

RootVC.swift:


class RootVC: UITabBarController {

override func viewDidLoad() {
super.viewDidLoad()
setupTabBarLayout()

}

private func setupTabBarLayout() {
// 1. Profile page
let profileVC = ProfileVC()
let profileVCBarItem = UITabBarItem(title: "Profil", image: UIImage(named: "profile_icon"), tag: 1)
profileVC.tabBarItem = profileVCBarItem

// 2. Search
let searchVC = SearchVC()
let searchVCBarItem = UITabBarItem(title: "Search", image: UIImage(named: "search_icon"), tag: 2)
searchVC.navigationItem.leftBarButtonItem = nil
searchVC.tabBarItem = searchVCBarItem

// 3. Meet
let meetVC = MeetVC()
let meetVC = SearchResultsVC()
let meetVCBarItem = UITabBarItem(title: "Meet", image: UIImage(named: "meet_icon"), tag: 3)
meetVC.tabBarItem = meetVCBarItem

// 4. Activities
let activitiesVC = ActivitiesVC()
let activitiesVCBarITem = UITabBarItem(title: "Activities", image: UIImage(named: "activities_icon"), tag: 4)
activitiesVC.tabBarItem = activitiesVCBarITem

// VC Setup
viewControllers = [profileVC, searchVC, meetVC, activitiesVC]
// Design settings
self.tabBar.backgroundColor = .lightButtonBg
self.tabBar.barTintColor = .darkMagenta
self.tabBar.tintColor = .customWhite
self.tabBar.unselectedItemTintColor = .lightButtonBg
self.tabBar.isTranslucent = false

}

最佳答案

试试这个

var vc = storyboard?.instantiateViewController(withIdentifier: "identifierForStoryboard

navigationController?.pushViewController(vc, animated: true)

然后观察是否出现view not in hierarchy之类的错误

关于ios - 以编程方式在 UITabBarController 和 UINavigationController 中呈现 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54406812/

25 4 0
文章推荐: html - site.css 中的 CSS 不适用于 asp.net 布局中的
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com