2014年1月2日星期四

[Android] 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 once ? If I want to have the operation each time you open , what should respond to events ah ?
------ Solution ---------------------------------------- ----
if it is returned to the main screen, press the home button , only to wake up again in response to the application 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 .
------ eference --------------------------------------- < br>
send notification to the current controller , specifically how to do , to demonstrate under it?
------ eference --------------------------------------- < br> Haha already get to know it. . . The easiest way is to call the 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];

没有评论:

发表评论