gpt4 book ai didi

ios - NSUserDefault 不加载首选项

转载 作者:行者123 更新时间:2023-11-28 22:20:13 24 4
gpt4 key购买 nike

我有类 Prefs.m 和方法:

+ (void) setString:(NSString *)valor chave:(NSString *)chave{

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

[prefs setObject:valor forKey:chave];

[prefs synchronize];
}

+ (NSString *) getString:(NSString *)chave{

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

NSString *valor = [prefs stringForKey:chave];

return valor;
}

然后我在类 LoginController.m 中设置首选项:

//Guarda informações do usuário no NSUserDefault
[Prefs setString:strID chave:@"prefID"];
[Prefs setString:usrNome chave:@"prefNome"];
[Prefs setString:usrEmail chave:@"prefEmail"];

但是当我在类 IndicationViewController.m 中加载首选项时:

//Busca por informações do usuário se não tem o ID na prefs
int intID = [Prefs getInteger:@"prefID"];

返回值 = 0。但是在设置的 prefs 中,该值为 1。为什么?

最佳答案

改变这个:

int intID = [Prefs getInteger:@"prefID"];

对此:

int intID = [[Prefs getString:@"prefID"] intValue];

或者对此:

NSString *prefID = [Prefs getString:@"prefID"];

关于ios - NSUserDefault 不加载首选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20624816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com