How to Add Multiple Buttons in UIAlertView in IOS !

If you are thinking to add multiple buttons in a alert view in IOS , Its very simple now.

you need to do few lines of code.

please take a look at the below lines of code.

@interface YourViewController : UIViewController

 

- (IBAction)YourButtonAction:(id)sender
{
UIButton *TickButton=(UIButton *)sender;


NSMutableArray *myArray1 = [[NSMutableArray alloc] initWithObjects:@“Title1”,@“Title2”, @"Title3”, @"Title4”,@“Title5”,@“Title6”, nil];

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
message:nil delegate:self
cancelButtonTitle:@"Cancel" otherButtonTitles:nil];

alertView.alertViewStyle = UIAlertViewStyleDefault;

for(NSString *buttonTitle in myArray1)
{
[alertView addButtonWithTitle:buttonTitle];
}


[alertView show];
}

 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

NSString *title = [alertView buttonTitleAtIndex:buttonIndex];

if([title isEqualToString:@"Title1"])
{
// write your code here
}
else if([title isEqualToString:@"Title2”])
{
// write your code here
}
else if([title isEqualToString:@"Title3”])
{
// write your code here
}
else if([title isEqualToString:@"Title4”])
{
// write your code here
}
}

tips & tricks

Join 7,719 other subscribers

interview questions


Algorithm Android Android Studio API APP Programming Apps blogging Browser CheatSheets Code Config CSS DATABASE dsa error Features HTML HTML5 IDE installation Interview Questions IOS iPhone javascript Mac objective-c OneDrive OS Placeholder Programming quicktips SDK SEO Settings SMO SQL swift swiftUI Teams Tips & Tricks Tools UI Web Wordpress Xcode


Archives

One response to “How to Add Multiple Buttons in UIAlertView in IOS !”

  1. where is nsuserdefaults stored ? – MyCodeTips

    […] Read Also : How to Add Multiple Buttons in UIAlertView in IOS ! […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from CODE t!ps

Subscribe now to keep reading and get access to the full archive.

Continue reading