NEW: Learn to build amazing SwiftUI apps for macOS with my new book! >>

Project 7 Only 'Most Recent' shows on tabBarItem

Forums > Swift

I can't seem to get the 'TopRated' to show up.

Here is my code from AppDelegate

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    if let tabBarController = window?.rootViewController as? UITabBarController {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "NavController")
        vc.tabBarItem = UITabBarItem(tabBarSystemItem: .topRated, tag: 1)
        tabBarController.viewControllers?.append(vc)
    }

    return true
}

I have "NavController" in the Navigation Controller Storyboard ID.

My version of xCode is 12.2.

1      

Solved! Moved the above to SceneDelegate.

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

    if let tabBarController = window?.rootViewController as? UITabBarController {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "NavController")
        vc.tabBarItem = UITabBarItem(tabBarSystemItem: .topRated, tag: 1)
        tabBarController.viewControllers?.append(vc)
    }

    guard let _ = (scene as? UIWindowScene) else { return }
}

2      

Thank you for posting this as I had the same problem. If this is an update to Xcode that needs code to be changed then there needs to be a note on the tutorial about it. I'll message Paul.

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Spend less time managing in-app purchase infrastructure so you can focus on building your app. RevenueCat gives everything you need to easily implement, manage, and analyze in-app purchases and subscriptions without managing servers or writing backend code.

Get Started

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.