0

I am a beginner in iOS development, and yesterday I learned about the UIAlertViewDelegate protocol from the Apple developer website.

I used -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex for managing the buttonindex and the performing the specific task.

However, when I use 2 UIAlertViews on the same outlet, they both use the same UIAlertViewDelegate protocol. How can I use different delegates for the other UIAlertView in my application?

Also, how can I change the default design of the UIAlertView in my Application?

rebello95
  • 8,486
  • 5
  • 44
  • 65

1 Answers1

4

Your UIAlertView has a property called tag. After you instantiate your alert view, set its tag:

myAlertView.tag = 1;

Use a different tag value for each of your alert views.

In your call back method, check the tag first to determine which alert view was dismissed and handle accordingly:

if (alertView.tag == 1) {
    //alert view 1 was dimissed, handle that
} else if (alertView.tag == 2) {
    //alert view 2 was dismissed
}
Peter Pei Guo
  • 7,770
  • 18
  • 35
  • 54