作爲在新迅速從故事板作爲RootViewController的實例化的viewController,我試圖用故事板使用去的LoginController下面的代碼無法在迅速
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
var type = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound;
var setting = UIUserNotificationSettings(forTypes: type, categories: nil);
UIApplication.sharedApplication().registerUserNotificationSettings(setting);
UIApplication.sharedApplication().registerForRemoteNotifications();
var navCtrl = UINavigationController();
var isLoggedIn = NSUserDefaults.standardUserDefaults().boolForKey(USERDEFAULT_ISLOGGEDIN);
if(isLoggedIn)
{
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var mainController: CategoriesController = mainStoryboard.instantiateViewControllerWithIdentifier(SEGUE_CATEGORIES) as CategoriesController
navCtrl.pushViewController(mainController, animated: true);
}
else
{
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var mainController: LoginController = mainStoryboard.instantiateViewControllerWithIdentifier(SEGUE_LOGIN) as LoginController
navCtrl.pushViewController(mainController, animated: true);
}
self.window?.rootViewController = navCtrl;
self.window?.makeKeyAndVisible();
return true
}
但是它只是顯示空白屏幕。將navController分配爲rootViewController有什麼不妥?
'self.window' is nil?在兩次調用中將'self.window?'替換爲'self.window!'。如果window是零,那可能是錯誤的,所以你應該強制解包。 – 2015-02-06 11:06:25
它給壞的錯誤然後@MatthiasBauch – 2015-02-06 11:08:52