- (void)applicationWillResignActive和save string - > ERROR

时间:2011-06-16 12:49:26

标签: iphone objective-c xcode application-settings

我想在重新加载App之后比较两个字符串。 (漫步和新闻宣布为全球性)

但是如果我在 -applicationWillEnterForeground:中调用字符串' strold ',我会收到以下错误消息:

0x011eca62< + 0022>推%edi

0x011eca63< + 0023> mov 0x8(%edx),%edi(BAD EXIT FOR THE LINE)

- (void)applicationWillEnterForeground:(UIApplication *)application{

    opendate = [NSDate date];
    NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    strnew = [formatter stringFromDate:opendate];
    NSLog(@"Active %@",strnew);
    NSLog(@"Inctive %@",strold);


}


- (void)applicationWillResignActive:(UIApplication *)application{

    closedate = [NSDate date];
    NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    strold = [formatter stringFromDate:closedate];

}

我只想检查一天是否实际发生了变化。 显着时间方法对我没用。

1 个答案:

答案 0 :(得分:2)

您必须retain strold,因为它是autorelease d。

strold = [[formatter stringFromDate:closedate] retain];

self.strold = [formatter stringFromDate:closedate];

如果strold被定义为保留属性。