For iOS 8 and above Apple have introduced UIAlertController to present action Sheet and alerts.
In order to present alert set preferredStyle to UIAlertControllerStyleAlert and for actionSheet preferredStyle to UIAlertControllerStyleActionSheet of your UIAlertController.
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
//change preferredStyle to UIAlertControllerStyleActionSheet in case of action Sheet
To add button and their action:
UIAlertAction* okbttn = [UIAlertAction actionWithTitle:@OK style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@" ok clicked);
}];
[alertController addAction: okbttn];
UIAlertAction* cancelbttn = [UIAlertAction actionWithTitle:@cancel style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
[alertController addAction: cancelbttn];
to add textField in alertView :
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder=@"name";
}];
[self presentViewController:alertController animated:YES completion:nil];
0 Comment(s)