gpt4 book ai didi

swift - 如何显示标签栏 Controller ?

转载 作者:行者123 更新时间:2023-11-30 11:10:35 25 4
gpt4 key购买 nike

我已经尝试了一切方法来将标签栏 Controller 安装到 MainViewController 上,但似乎没有任何效果。

简单介绍一下应用程序的工作原理:Storyboard 条目是 AppContainerViewController,如果用户登录,则 MainViewController 会按预期显示,但是我无法让 MainVC 成为 TabBar Controller 来显示选项卡栏,以便用户导航到各个页面。

我做错了什么?!

应用程序容器 View Controller

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)
}
}

主视图 Controller

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()
}
}

最佳答案

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

关于swift - 如何显示标签栏 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52216171/

25 4 0