0
當我把下面的代碼中viewDidLoad中我返回警告:試圖提出其看法並不在窗口層次警報
警告:試圖提出有關誰的觀點是不是在窗口層次!
我試着把它放在ViewdidAppear中,但是然後警報沒有顯示出來。
我該如何解決這個問題?
代碼:
UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"Login"
message: @"Input username and password"
preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Public Key";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Private Key";
textField.textColor = [UIColor blueColor];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.secureTextEntry = YES;
}];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSArray * textfields = alertController.textFields;
UITextField * publickey = textfields[0];
UITextField * privatekey = textfields[1];
[[NSUserDefaults standardUserDefaults] setObject:publickey.text forKey:@"privateKey"];
[[NSUserDefaults standardUserDefaults] setObject:privatekey forKey:@"publicKey"];
NSLog(@"%@:%@",publickey.text,privatekey.text);
}]];
感謝。
它確實現在在viewDidAppear中工作。 – Anoniem