当我在 iOS4.2 上运行以下代码时,会保存默认值。但是当我在 5.0 中运行时,当用户关闭(完全关闭应用程序)时,它们会迷路。
我错过了什么?谢谢
- (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";
列表: