我试图实现的是当用户在3次后打开应用程序时显示UIAlertview。我在ViewDidAppear的ViewController中使用下面的代码,但是每次打开应用程序时都会显示UIAlertview。有人能告诉我我在这里做错了吗?3启动后显示UIAlertview应用程序
int launches = [[NSUserDefaults standardUserDefaults] integerForKey:@"launchCount"];
if (launches > 3) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"My Alert"
message:@"Some message" delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
[[NSUserDefaults standardUserDefaults] setInteger:launches+1 forKey:@"launchCount"];
编辑:我也得到一个NSInteger(又名'长')'int'警告。这可能是为什么它不起作用的问题吗?
要修复警告,请将'int'更改为'NSInteger'。 – AdamPro13 2014-10-20 20:17:19
[显示uialertview 3次后打开应用程序?]的可能重复?(http://stackoverflow.com/questions/26471780/show-uialertview-after-opening-an-app-after-3-times)什么目的是有两次问相同的问题? – Popeye 2014-10-30 13:16:57