- (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提前
答案 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]]
从超级视图中删除该视图,然后再次显示警报。