Objective-C UIAlertController to Show DialogBox (Alert Box) with Multiple Buttons

Malisha Tharindu
1 min readAug 11, 2020
objective C UIAlertViewController

#objectiveC #UIAlertViewController #iOSDevelopment

Here I use UIAlertController to make an alert/dialog box.

//Initialize UIAlertController and its title and subtitle
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@”Tittle” message:@”Subtitle” preferredStyle:UIAlertControllerStyleAlert];
//Button 1
UIAlertAction *actionButton1 = [UIAlertAction actionWithTitle:@”Button1” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//code for performing acctions to be excuted when click Button1
NSLog(@”Button 1 Pressed”);
}];//Button 2
UIAlertAction *actonButton2 = [UIAlertAction actionWithTitle:@”Button2” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//code for performing acctions to be excuted when click Button2
NSLog(@”Button 2 Pressed”);
}];[alert addAction: actonButton1];[alert addAction: actonButton2];[self presentViewController:alert animated:YES completion:^{//code for performing acctions to be excuted when UIAlertController is startedNSLog(@”dffefe”);}];

you can Implement this code block inside action or function.

--

--

Malisha Tharindu

Entrepreneur | iOS Developer | Web Developer with more than 5 Years of Experience. Founder of Learn with Malisha