如何显示标签栏控制器?

问题描述 投票:0回答:1

我已经尝试了所有东西,以获得MainViewController上的tabbar控制器,似乎没有任何工作。

关于应用程序如何工作的快速简介:Storyboard条目是AppContainerViewController,如果用户登录,那么MainViewController就会出现,但是我不能让MainVC成为TabBar控制器来显示用户导航到各个页面的标签栏。

我究竟做错了什么?!

app containerviewcontroller

class AppContainerViewController: UIViewController {

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        AppManager.shared.appContainer = self
        AppManager.shared.showApp()
    }
}

import UIKit
import Firebase
import FirebaseDatabase
import FBSDKLoginKit

class AppManager {

    static let shared = AppManager()

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    var appContainer: AppContainerViewController!

    private init() {}

    func showApp() {

        var viewController: UIViewController

        if (Auth.auth().currentUser == nil) && (FBSDKAccessToken.current() == nil) {
            viewController = storyboard.instantiateViewController(withIdentifier: "LoginViewController")
        } else {
            viewController = storyboard.instantiateViewController(withIdentifier: "MainViewController")
        }

        appContainer.present(viewController, animated: true, completion: nil)
    }

    func logout() {
        let loginManager = FBSDKLoginManager()
        loginManager.logOut()

        try! Auth.auth().signOut()
        appContainer.presentedViewController?.dismiss(animated: true, completion: nil)
    }
}

主视图控制器

import UIKit
import Firebase
import FirebaseDatabase
import FBSDKShareKit

class MainViewController: UIViewController {

    @IBOutlet weak var name: UILabel!
    @IBOutlet weak var email: UILabel!

    @IBAction func logoutPressed(_ sender: Any) {
        AppManager.shared.logout()
    }

    @IBAction func fbSharePressed(_ sender: Any) {

        let content = FBSDKShareLinkContent()
        content.contentURL =  URL(string: "https://advice.com")
        content.quote = "Hey, I'm one step closer to getting into the college of my dreams with this app.  Download it and let's go together!"

        let dialog : FBSDKShareDialog = FBSDKShareDialog()
        dialog.fromViewController = self
        dialog.shareContent = content
        dialog.mode = FBSDKShareDialogMode.automatic
        dialog.show()
    }

    func userProfile() {

        guard let uid = Auth.auth().currentUser?.uid else { return }

        let ref = Database.database().reference()
        ref.child("users").child(uid).observeSingleEvent(of: .value, with: { (snapshot) in
            guard let dict = snapshot.value as? [String: Any] else { return }
            let user = CurrentUserProfile(uid: uid, dictionary: dict)
            self.name.text = user.name
            self.email.text = user.email
        }, withCancel: nil)
    }

    override func viewDidLoad() {        
        super.viewDidLoad()

        userProfile()
    }
}
swift viewcontroller tabbarcontroller
1个回答
0
投票

鸡蛋在我脸上。我的故事板ID是错误的,并通过故事板将MainViewController嵌入到TabBarController中,然后将MainVC的故事板ID应用到TabBarController就可以了。

© www.soinside.com 2019 - 2024. All rights reserved.