Wednesday, January 8, 2014

Ask you back to the main screen, reopen app, view the response is what event?

Built a single view of the program, at the first time of entry can respond viewDidLoad, and then return to the main screen, and then open the app when viewDidLoad not responded, for a viewWillAppear and viewDidAppear does not work, do not they all just response time ? If I want to have the operation each time you open, what should respond to events ah?
Reply:
If it is returned to the main screen, press the home button, only to wake up again respond when the application-level processing. appdelegate.h file
 - (void) applicationWillResignActive: (UIApplication *) application 

Will be called. Press the home button controller does not have any pre-treatment, but you can through the above application-level event handler to send notification to the current controller, so that the current controller to handle it.
Reply:
cited a floor zhanglei5415 reply:
will only respond if it is returned to the main screen, press the home key, to wake up again when the application-level processing. appdelegate.h file
 - (void) applicationWillResignActive: (UIApplication *) application 

Will be called. Press the home button controller does not have any pre-treatment, but you can through the above application-level event handler to send notification to the current controller, so that the current controller to handle it.

Send notification to the current controller, specifically how to do, to demonstrate under it?
Reply:
Haha already get to know it. . . The easiest way is to call a function
 
ViewController * controller = (ViewController *) (self.window.rootViewController);
[Controller test];

nocication can use the following code
 

NSNotification * ntf = [NSNotification notificationWithName: @ "chgValue" object: self];

NSNotificationCenter * ntfCenter = [NSNotificationCenter defaultCenter];

ViewController * controller = (ViewController *) (self.window.rootViewController);

[NtfCenter addObserver: controller selector: @ selector (getNtf :) name: @ "chgValue" object: self];

[[NSNotificationQueue defaultQueue] enqueueNotification: ntf postingStyle: NSPostNow coalesceMask: NSNotificationCoalescingOnName forModes: nil];

No comments:

Post a Comment