Skip to content

Instantly share code, notes, and snippets.

@congbo
Created May 15, 2014 09:50
Show Gist options
  • Save congbo/48b21079768f374954d2 to your computer and use it in GitHub Desktop.
Save congbo/48b21079768f374954d2 to your computer and use it in GitHub Desktop.
弹出带输入框的alertView
- (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