To Create a alertView with textField in Xcode 7.2 we can Use the the code below to handle the Yes and no action.
and also get the text of the textField. You can show this on a viewController.
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"Set title Here"
message:@"set Message Here"
preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.placeholder = @"placeholdertext";
}];
UIAlertAction* yesButton = [UIAlertAction
actionWithTitle:@"Yes"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
UITextField *myTextFiled = alert.textFields.firstObject;
NSLog(@"Text of the fiedld== %@",myTextFiled.text);
}];
UIAlertAction* noButton = [UIAlertAction
actionWithTitle:@"No"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
//Handel no, button
}];
[alert addAction:yesButton];
[alert addAction:noButton];
[self presentViewController:alert animated:YES completion:nil];
0 Comment(s)