UIAlert -> UIAlertController deprecation fix

This commit is contained in:
Scott Ludwig 2016-01-20 11:00:11 -08:00
parent ee2695b4ac
commit 589fdff1b3
3 changed files with 41 additions and 26 deletions

View File

@ -19,14 +19,13 @@
NSString *default_string_;
UIKeyboardType keyboard_type_;
BOOL secure_;
UIAlertView *alert_view_;
int cchMax_;
id<InputDelegate> delegate_;
}
- (id)init:(NSString *)title default:(NSString *)default_string
keyboardType:(UIKeyboardType)keyboard_type delegate:(id)delegate
maxChars:(int)cchMax secure:(BOOL)secure;
- (void)loadView;
maxChars:(int)cchMax secure:(BOOL)secure controller:(UIViewController *)controller;
- (void)loadAlert:(UIViewController *)controller;
@end
#endif // __INPUTCONTROLLER_H__

View File

@ -4,7 +4,7 @@
- (id)init:(NSString *)title default:(NSString *)default_string
keyboardType:(UIKeyboardType)keyboard_type delegate:(id)delegate
maxChars:(int)cchMax secure:(BOOL)secure {
maxChars:(int)cchMax secure:(BOOL)secure controller:(UIViewController *)controller {
title_ = title;
[title_ retain];
@ -15,9 +15,8 @@
[delegate_ retain];
cchMax_ = cchMax;
secure_ = secure;
alert_view_ = nil;
[self loadView];
[self loadAlert:controller];
return self;
}
@ -25,31 +24,48 @@
- (void)dealloc {
[title_ release];
[default_string_ release];
[alert_view_ release];
[delegate_ release];
[super dealloc];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)way
{
return way == UIInterfaceOrientationLandscapeRight;
}
- (void)loadAlert:(UIViewController *)controller {
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:title_
message:nil
preferredStyle:UIAlertControllerStyleAlert];
- (void)loadView {
UIAlertView *view = [[UIAlertView alloc] initWithTitle:title_
message:nil delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
alert_view_ = view;
alert_view_.alertViewStyle = secure_ ? UIAlertViewStyleSecureTextInput : UIAlertViewStylePlainTextInput;
[alert_view_ textFieldAtIndex:0].delegate = self;
[alert_view_ show];
}
[alert addTextFieldWithConfigurationHandler:^(UITextField *text_field) {
text_field.text = default_string_;
text_field.keyboardType = keyboard_type_;
text_field.autocapitalizationType = UITextAutocapitalizationTypeNone;
text_field.autocorrectionType = UITextAutocorrectionTypeNo;
text_field.spellCheckingType = UITextSpellCheckingTypeNo;
text_field.enablesReturnKeyAutomatically = YES;
if (secure_) {
[text_field setSecureTextEntry:YES];
}
text_field.delegate = self;
}];
- (void)alertView:(UIAlertView *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex > 0) {
[delegate_ onDone:self text:[alert_view_ textFieldAtIndex:0].text];
}
UIAlertAction *cancel_action = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
}];
[alert addAction:cancel_action];
UIAlertAction *ok_action = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
UITextField *text_field = [alert.textFields firstObject];
[delegate_ onDone:self text:text_field.text];
}];
[alert addAction:ok_action];
[controller presentViewController:alert animated:YES completion:nil];
UITextField *text_field = [alert.textFields firstObject];
[text_field becomeFirstResponder];
}
- (BOOL)textField:(UITextField *)textField

View File

@ -128,7 +128,7 @@
InputController *input_controller = [[InputController alloc]
init:title default:def keyboardType:keyboardType
delegate:self maxChars:maxAsk_ secure:secureAsk_];
delegate:self maxChars:maxAsk_ secure:secureAsk_ controller:self];
input_controller_ = input_controller;
}