我试图在NSUserdefault中存储信息.我的目的是在用户第一次启动应用时向用户显示弹出消息.我的代码如下:
//In my view did load method self.prefs = [NSUserDefaults standardUserDefaults]; self.firstTimeLaunchingApp = [prefs integerForKey:@"firstTimeLaunchx"]; [self tableRefresh]; //This method is called after the refresh button is clicked -(void)tableRefresh { [self displayFirstTimeMessage]; //Other codes ommited } //Method to display pop up if first time user -(void) displayFirstTimeMessage { if (self.firstTimeLaunchingApp != 1 ) { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Welcome!" message:@"Thanks for using the app!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; [prefs setInteger:1 forKey:@"firstTimeLaunchx"]; [prefs synchronize]; } }
我在这里遇到的问题是,当我第一次启动应用程序时,会出现警告弹出窗口(这是预期的),但是当我点击刷新按钮(它将再次触发“displayFirstTimeMessage”)时,我仍然会看到警报弹出窗口不是预期的.我为NSUserDefault设置密钥的方式有问题吗?
注意:如果我停止并重新启动应用程序,则不会显示弹出窗口.