import UIKit
class StartUp: UIViewController {
var window: UIWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
var window2: UIWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
var window3: UIWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
var window4: UIWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
var startController: UIViewController?
var startController2: UIViewController?
var startController3: UIViewController?
var startController4: UIViewController?
var newViewController = false
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
override func viewDidLoad() {
super.viewDidLoad()
var currentUser = PFUser.currentUser()
//Get current app config (position codes and check if app is active)
if (checkInternetConnection() == true) {
PFConfig.getConfigInBackgroundWithBlock {
(parseConfig: PFConfig?, error: NSError?) -> Void in
//Determine where to start app
//Already logged in
if (currentUser != nil) {
self.startController = self.mainStoryboard.instantiateViewControllerWithIdentifier("TabBar") as TabBar
}
//Not logged in
else {
self.startController = self.mainStoryboard.instantiateViewControllerWithIdentifier("loginStart") as UINavigationController
}
self.window.rootViewController = self.startController
self.window.makeKeyAndVisible()
//If the app is disabled, display the inactive/disabled/error screnen.
if (parseConfig?["active"] as Bool? == false) {
self.startController = self.mainStoryboard.instantiateViewControllerWithIdentifier("block") as AppBlock
self.window2.rootViewController = self.startController
self.window2.makeKeyAndVisible()
}
}
}
else {
//Already logged in
if (currentUser != nil) {
self.startController = self.mainStoryboard.instantiateViewControllerWithIdentifier("TabBar") as TabBar
}
//Not logged in
else {
self.startController = self.mainStoryboard.instantiateViewControllerWithIdentifier("loginStart") as UINavigationController
}
self.window3.rootViewController = self.startController
self.window3.makeKeyAndVisible()
self.startController = self.mainStoryboard.instantiateViewControllerWithIdentifier("block") as AppBlock
self.window4.rootViewController = self.startController
self.window4.makeKeyAndVisible()
}
}
}
我认为这是一种奇怪的情况。如果第一个if语句checkInternetConnection()
为真,我继续确定要显示的窗口/视图。这里的一切都很完美。但是,在else
部分中,不会显示任何窗口/视图。我无法弄清楚为什么会发生这种情况......它真的很奇怪,它在一个部分工作但不在另一部分......
有什么想法吗?
在某些情况下,还会创建两个窗口/视图。这会是个问题吗?我不这么认为,因为如果parseConfig
为假,则会创建并正确显示两个窗口。