---
title: "How to use UIAlertController in Objective-C iOS"  
description: "UIAlertController introduced in iOS 8 .UIAlertController replaces the UIActionSheet and UIAlertView classes. UIAlertController  can be used for displa"  
author: "Sunil Singh"  
published: 2017-01-11  
updated: 2018-03-17  
canonical: https://www.mindstick.com/blog/11253/how-to-use-uialertcontroller-in-objective-c-ios  
category: "ios"  
tags: ["iphone", "ios", "iphone sdk", "objective c", "uiview"]  
reading_time: 1 minute  

---

# How to use UIAlertController in Objective-C iOS

UIAlertController introduced in iOS 8 .UIAlertController replaces the UIActionSheet and UIAlertView classes. UIAlertController can be used for displaying [alerts](https://answers.mindstick.com/qa/102510/what-is-the-purpose-of-google-alerts-for-notifications) ,confirmation alert ,act as [action](https://www.mindstick.com/forum/155751/define-action-method-in-mvc) sheet and used for [login](https://www.mindstick.com/blog/206/login_form) [purpose](https://yourviews.mindstick.com/view/247/no-fail-policy-failing-its-purpose) etc. If you want to add [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) to UIAlertController there is a [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) [named](https://answers.mindstick.com/qa/44918/what-is-a-no-day-yet-named-motion) UIAlertAction .

UIAlertAction provides an action [handler](https://www.mindstick.com/forum/2470/jquery-autocomplete-using-handler) with [block](https://www.mindstick.com/forum/157599/explain-the-process-control-block-pcb-in-the-operating-system) which gets called when the button get tapped. Here we are using UIAlertController for login purpose below is the sample of UIAlertController -

\

```
UIAlertController
*alertView = [UIAlertController
alertControllerWithTitle:
@"User
Login"message:
@"Input
username and password"preferredStyle:UIAlertControllerStyleAlert];[alertView
addTextFieldWithConfigurationHandler:^(UITextField
*textField) {textField.placeholder
= @"email";
//
email as username in my casetextField.textColor
= [UIColor
blueColor];textField.clearButtonMode
= UITextFieldViewModeWhileEditing;textField.borderStyle
= UITextBorderStyleRoundedRect;}];[alertView
addTextFieldWithConfigurationHandler:^(UITextField
*textField) {textField.placeholder
= @"password";textField.textColor
= [UIColor
blueColor];textField.clearButtonMode
= UITextFieldViewModeWhileEditing;textField.borderStyle
= UITextBorderStyleRoundedRect;textField.secureTextEntry
= YES;}];[alertView
addAction:[UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction
*action) {NSArray
* textfields = alertView.textFields;UITextField
* userNameField = textfields[0];UITextField
* passwordFiled = textfields[1];NSLog(@"email=%@
pasword=%@",userNameField.text,passwordFiled.text);/*
 NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]
initWithEntityName:@"Employee"];[fetchRequest
setPredicate:[NSPredicate predicateWithFormat:@"email==%@ AND
password==%@",userNameField.text,passwordFiled.text]];NSArray
*arrayList   = [[appDelegate.managedObjectContext
executeFetchRequest:fetchRequest error:nil] mutableCopy];if(arrayList.count>0){[self
performSegueWithIdentifier:@"showUsers" sender:self];}else{NSLog(@"login
failed");}
*/}]];[alertView
addAction:[UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction
 *action){[alertView
dismissViewControllerAnimated:YES
completion:nil];}]];[self
presentViewController:alertView
animated:YES
completion:nil];
```

\

Following is the [screen](https://www.mindstick.com/forum/33644/loading-screen-during-ajax-call) shot of UIAlertController -

![How to use UIAlertController in Objective-C iOS](https://www.mindstick.com/blogs/8e7b1895-8f74-436f-b772-2fc8416747bf/images/5328ae9d-5dcd-48e3-a4d4-a40deb531b28.png)\

---

Original Source: https://www.mindstick.com/blog/11253/how-to-use-uialertcontroller-in-objective-c-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
