开发者

iPhone viewDidBecomeActive (or just resuming from background) questions

I've been researching this for a few hours and I'm still unsure if I am even heading in the right direction.

What I would like to do: When my app is loaded, I need to determine if it's the first time the user has loaded the app that day.

How I was planning on doing it: I made some labels to display the current day and last day that they used the app. (See sample code bel开发者_开发百科ow).

-(void)pressStatus{
NSString * currentDay;
currentString = currentDay.text;
NSString * lastDay;
lastString = lastDay.text;
if([currentDay isEqualToString: lastDay]){
    status.text = @"same";
}
else {
    status.text = @"different";
    [self autoReset];

}

So, it does what I need to do, but at the push of a button. Instead, I would like it to happen as soon as the app loads from the background. From what I read, I think I should use viewDidBecomeActive, but I'm not fully understanding it. I've never used the delegate as of yet and at this point everything I'm reading is confusing me more than the last.

Questions

  1. Is viewDidBecomeActive the best way to do this?

  2. If so, can I call the pressStatus function in the MainViewController from within applicationDidBecomeActive in the delegate?

Thanks in advance.


This web page has some very nice flow charts which describe app foregrounding etc.:

http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging

There's no viewDidBecomeActive btw, are you thinking of something else?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜