I have two UIAlertViews in same view controller and I want to use the delegate method
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger) buttonIndex
This method will get called when a button in an alert view is pressed. However both alert views will call the same method.
How can I different the two alert views?
Set the
tagproperty to different values when you display the alert. It’s just an integer and can be queried in the callback/delegate method.Here’s an example (using an ActionSheet rather than an AlertView, but the principle is exactly the same):
Then in your selector:
Of course, you’d use constants rather than literal values, localised strings, etc, but that’s the basic idea.