0

我試圖設置一個值到我的tabbar中的標籤欄項目,這是在故事板上創建的,每次通過我的應用程序委託推送遠程通知時。我不斷收到此錯誤:更新Swift Coulld中的TabBar徽章不是類型UINavigationController的轉換值

Could not cast value of type 'UINavigationController' (0x19632c0b0) to 'UITabBarController' (0x19632d230). 

代碼:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
    var tabBarController = self.window!.rootViewController as! UITabBarController 
     ... 
     var tabArray = tabBarController.tabBar.items as NSArray! 
     var tabItem = tabArray.objectAtIndex(3) as! UITabBarItem 
     tabItem.badgeValue = "34" 
     ... 
    } 
    println("notification") 
    //scheduleNotification() 
} 
+0

是否可以看到故事板的佈局? – ndmeiri

回答

0

您發佈第一行代碼

var tabBarController = self.window!.rootViewController as! UITabBarController 

試圖迫使向下轉換到UITabBarController,但self.window! .rootViewController是一個UINavigationController。在故事板中,確保將標籤欄控制器設置爲「初始視圖控制器」。

+0

但是當我將標籤欄控制器設置爲初始視圖控制器時,所有東西都混亂起來。 – MasterWizard

+0

@AhmedNassar有可能看到你的故事板的截圖嗎? – ndmeiri