Get Instance of RootView in the AppDelegate
How do I get an instance of RootViewController in order to use code like:
rootViewController.progressView.progress =开发者_C百科 0.7
in the applicationDidFinishLauching
method in the App Delegate?
This works for me:
#import "CBAppDelegate.h"
#import "OPStringLocalization.h"
@implementation CBAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIViewController* rootController = [self.window rootViewController];
[rootController localizeStrings];
return YES;
}
@end
You can create an IBOutlet
of a float variable in your rootViewController
.Then you can init that variable in applicationDidFinishLaunching by the same code that you showed like this
rootViewController.progress = 0.7;
and in viewDidLoad
method of rootViewController
you can then show the progress of your progress View to 70 % or what ever you want.
Apparently you cannot do
rootViewController.progressView.progress = 0.7;
coz your progressView object is in archived state or frozen state or something like that.
so I think you can use this as a solution to your problem.
hope this helps
you usually have an instance available as an instance variable of the window object:
self.window.rootViewController
精彩评论