【发布时间】:2014-10-20 20:13:58
【问题描述】:
我想要实现的是当用户在 3 次后打开应用程序时显示 UIAlertview。我在 ViewDidAppear 的 ViewController 中使用下面的代码,但每次打开应用程序时都会显示 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(又名“long”)到“int”警告。这可能是它不起作用的问题吗?
【问题讨论】:
-
要修复警告,请将
int更改为NSInteger。 -
Show uialertview after opening an app after 3 times? 的可能重复项问同一个问题两次的目的是什么?
标签: ios objective-c xcode ios7 uialertview