我已经尽一切努力消除了使用MainViewController加载带有动态变量的Label或任何其他对象的延迟,并且似乎没有任何效果。
快速了解应用程序的工作原理:情节提要条目是AppContainerViewController,如果用户登录,则将显示MainViewController,但将变量加载到Labels,ImageViews等对象中时,MainVC会有很小的延迟。
我在做什么错?!仅供参考,AppContainerVC中的viewWillAppear和viewDidLoad“破坏”我的应用程序,从不显示MainVC。
import UIKit
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()
}
}