因爲我在一個Integer值中存儲一個Integer值到NSUserDefaults
,在很多地方使用它。在第一次的工作正常,但同時我關閉我的應用程序,然後再次打開它,我檢查已經選擇在過去feom NSUserDefaults
儲值的任何選項,用戶,但我沒在NSNotFound不能與NSUser一起使用默認
有些事情是錯誤的,我的情況下
這裏是我的檢查整數值的代碼是在有userdefault:
NSInteger selectedBusinessUnit = [[NSUserDefaults standardUserDefaults] integerForKey:@"selectedUnit"];
if (selectedBusinessUnit != NSNotFound){
//go to direct main screen.
}else {
// load Business unit screen for selection.
}
但它總能找到價值,即使我正在刪除應用程序,並reinastall它。
總是我的選定值是。
讓我知道這裏我的愚蠢的錯誤是什麼。
編輯:
[[NSUserDefaults standardUserDefaults] setInteger:sender.tag forKey:@"selectedUnit"];
[[NSUserDefaults standardUserDefaults] synchronize];
THNAKS。
朋友你可以顯示你的setInteger:forKey代碼? –
我相信你在設定價值時做錯了什麼。 –
請考慮'NSNotFound'是一個有效的整數值。這不等於'nil'或*鍵丟失*。正如答案中所述,如果密鑰丟失,'integerForKey'返回0。根本不同的標籤分配給'sender'(默認也是0)? – vadian