I'm extending Apple's template for lazy table image loading. I would like the following code to run when RootViewController is constructed.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
object: nil];
The problem is I don't how how RootViewController is constructed. I tried the following two methods, but they were never executed. I put NSLog
in those methods and they were never printed out.
- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil
- (id)init
I opened MainWindow.xib and noticed that it loads RootViewController as an IBOutlet in the UIApplicati开发者_开发问答onDelegate
. Now, RootViewController is a subclass of UIViewController
. So the question boils down to "how is an IBOutlet UIViewController constructed?"
You can executed the code you need to execute in the awakeFromNib method, this is called by the decoder once the outlet is created.
精彩评论