Created
May 15, 2014 09:50
-
-
Save congbo/48b21079768f374954d2 to your computer and use it in GitHub Desktop.
弹出带输入框的alertView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)addTaskButtonClicked:(id)sender | |
{ | |
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"NewTaskTitle", @"") | |
message:@"" | |
delegate:self | |
cancelButtonTitle:NSLocalizedString(@"NewTaskCancel", @"") | |
otherButtonTitles:NSLocalizedString(@"NewTaskConfirm", @""), nil]; | |
alertView.delegate = self; | |
alertView.tag = 0; | |
alertView.alertViewStyle = UIAlertViewStylePlainTextInput; | |
UITextField* alertTextField = [alertView textFieldAtIndex:0]; | |
alertTextField.placeholder = NSLocalizedString(@"NewTaskPlaceholder", @""); | |
[alertView show]; | |
} | |
#pragma mark - UIAlertViewDelegate | |
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex | |
{ | |
if (alertView.tag == 0) { | |
UITextField* alertTextField = [alertView textFieldAtIndex:0]; | |
if (buttonIndex == 1) { | |
NSString* taskName = alertTextField.text; | |
if (taskName.length > 0) { | |
[[self.allViewControllers objectAtIndex:1] addTask:taskName]; | |
} | |
} | |
[alertTextField resignFirstResponder]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment