0

UIAlertView当用户运行应用程序时,我有一个简单的显示。它有这样的结构:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Welcome!", "")
                                                message:NSLocalizedString(@"This is a welcome message.", "")                             
                                               delegate:nil
                                      cancelButtonTitle:@"OK" 
                                      otherButtonTitles: nil];
[alert show];
[alert release];

问题是,例如,我如何自定义它以显示每 5 次运行?

提前致谢 ;)

4

2 回答 2

2

AppDelegate 类中会有一个方法,例如

- (void)applicationDidBecomeActive:(UIApplication *)application

现在在此方法中创建一个 NSUSerdefaults 并生成一个整数并增加该整数并将其保存在 NSUserdefaults

现在每次应用程序启动时都会调用该方法并且整数将递增

现在在该方法中设置 if 条件,如下所示

if(your integer which has nsuserdefaults >=5)
{
   your alertview
    again here make your nsinteger  to Zero which is stored in nsuserdefaults 
     your integer which has nsuserdefaults =0
} 

这是您第二个问题的答案,每次应用程序运行 5 次后。将弹出警报让我知道它是否有效..!!!! 快乐编码!!!!

于 2012-11-01T12:27:49.990 回答
1

您可以使用NSUserDefaults存储键的应用程序执行计数AppRunCount(您可以引入自己的键名):

int runCount = [[NSUserDefaults standardUserDefaults] integerForKey:@"AppRunCount"] + 1

[[NSUserDefaults standardUserDefaults] setInteger:runCount forKey:@"AppRunCount"];

if (runCount <= 5) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Welcome!", "")
                                            message:NSLocalizedString(@"This is a welcome message.", "")                             
                                           delegate:nil
                                  cancelButtonTitle:@"OK" 
                                  otherButtonTitles: nil];
    [alert show];
    [alert release];
}

您只需将上面的代码添加到viewDidLoad

于 2012-10-31T08:55:23.733 回答