As you can see in the title, I want to set the badge in TabBarController's tabbar from the event in AppDelete, but I don't know how to browse TabBarController's tabbar.This may be a rudimentary question, but I would like to ask you to teach me.
Specifically, I would like to update the contents of the badge for the fourth time on the four tabs when the Push Notification event fires.
func application(application:UIAPlocation, didReceiveRemoteNotification userInfo: [NSObject:AnyObjevt]){
lettb = TabBarController()
tb.tabbar.items![3].badgeValue="3"/*new or 3etc...*/
↑ Of course, this is an error.
}
As you can see in this question, AppDelegate's firing events (other than notification events) do not know how to manipulate the contents of other View text boxes and labels.
For example, if you press the FirstViewController button, you can change the value of the text box in the SecondViewController.For the first time in Swift, we do not understand the basics of operation between different View classes, including AppDelegate.
swift
If you haven't changed the contents of AppDelegate.swift (although of course you have added code), you have the property window
, right?
iflet tabBarController=self.window?.rootViewController as?UITabBarController{
}
You can retrieve the TabBar Controller from the .
iflet tabBarController=self.window?.rootViewController as?UITabBarController{
tabBarController.tabBar.items![3].badgeValue="3"
}
It seems that the basic window cannot be retrieved from iOS13 without SceneDelegate, so I could go there by calling it sceneWillEnterForeground(_scene:UIScene)
!
class SceneDelegate:UIResponder, UIWindowSceneDelegate{
var window —UIWindow?
func sceneWillEnterForeground(_scene:UIScene){
iflet tabBarController=self.window?.rootViewController as?UITabBarController{
tabBarController.tabBar.items![3].badgeValue="3"
}
}
}
© 2024 OneMinuteCode. All rights reserved.