当应用程序进入ios中的活动进程的后台进程时,我将显示可编辑的alertview

时间:2016-03-11 04:01:42

标签: ios uialertview

hii朋友我将创建密码类型alertview。当应用程序进入活动模式时,密码alertview display.than我将最小化第二次应用程序后比我打开应用程序比时间两次显示alertview进入app.like上次背景alertview和当前alertview.but我想随时只有一个alertview。 这是我的代码 Appdelegate.m

 - (void)applicationDidEnterBackground:(UIApplication *)application {


    NSLog(@"applicationDidEnterBackground");
    UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Enter Password?"
                                                      message:nil
                                                     delegate:self
                                            cancelButtonTitle:nil
                                            otherButtonTitles:@"Continue", nil];

    [message setAlertViewStyle:UIAlertViewStyleSecureTextInput];
    UITextField *textField = [message textFieldAtIndex:0];
    assert(textField);
    textField.keyboardType = UIKeyboardTypeNumberPad;
    [message show];

       // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {




}

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *password = [defaults objectForKey:@"name"];

    NSString *inputText = [[alertView textFieldAtIndex:0] text];
    if( [inputText isEqualToString:password] )
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

请解决我的问题friends.thanks提前

2 个答案:

答案 0 :(得分:2)

在Appdelegate.m文件下面添加此行,您可以在其中创建alertview。

   [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillResignActiveNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification){
        [message dismissWithClickedButtonIndex:0 animated:NO];
    }];

答案 1 :(得分:0)

当您第二次打开应用程序时,循环浏览所有子视图,当您找到匹配项时:

    isKindOfClass:[UIAlertView class]]

从超级视图中删除该视图,然后再次显示警报。