NSUserDefaults似乎只适用于较旧的iOS?

时间:2012-06-10 23:09:41

标签: objective-c cocoa-touch nsuserdefaults

当我在iOS4.2上运行以下代码时,会保存默认值。 但是当我在5.0中运行时,他们会在用户关闭时丢失(完全关闭应用程序)。

我错过了什么? THX

- (void) setupSave:(UIButton*)btn
{
    //save IP and Port
    strTcpIpAddress = [tvTcpIpAddress text];
    strTcpPort = [tvTcpPort text];
    [[NSUserDefaults standardUserDefaults] setObject:strTcpIpAddress forKey:@"tcpIpAddress"];
    [[NSUserDefaults standardUserDefaults] setObject:strTcpPort forKey:@"tcpPort"];

    [tvTcpIpAddress resignFirstResponder];
    [tvTcpPort resignFirstResponder];
}

OnStartUp:
    //NSUserDefaults
    strTcpIpAddress = [[NSUserDefaults standardUserDefaults] stringForKey:@"tcpIpAdress"];
    strTcpPort = [[NSUserDefaults standardUserDefaults] stringForKey:@"tcpPort"];

    //userName = NULL;
    if(strTcpIpAddress == NULL) strTcpIpAddress = @"10.0.0.7";
    if(strTcpPort == NULL) strTcpPort = @"4000";

plist中:

enter image description here

0 个答案:

没有答案