我有一個包含兩個標籤的視圖控制器。我想從AppDelegate中設置這些標籤的值。我遇到了崩潰,當我調試它時,我發現標籤爲零。 這是我如何調用在AppDelegate的視圖控制器:Swift:在AppDelegate中設置標籤文本
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
self.homeViewController = self.storyboard.instantiateViewControllerWithIdentifier("homeViewController") as! HomeViewController
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(checkForReachability), name: ReachabilityChangedNotification, object: nil)}
而且checkForReachability
裏面我設置的標籤文本。例如:
self.homeViewController.labelNetworkType.text = "WIFI";
我已經驗證標籤已連接到視圖控制器。 我該如何解決這個問題?我有這個問題,因爲我的應用程序是一個單一的視圖應用程序,我記得AppDelegate中的主視圖?
請幫
在測試完你的測試後代碼,標籤不是零,但它始終是顯示的默認值 –
哇感謝兄弟它的作品就像一個魅力... – Learner