Hi so say I have this code:
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Yay"
message: msg
delegate: self
cancelButtonTitle: @"Proceed..."
otherButtonTitles: @"1", @"2", nil];
How do I control the other buttons “1” and “2”? (Suppose all other necessary code is in place, such as the undefined variable msg)
Thanks!
You need to set the
delegateproperty of yourUIAlertViewinstance (i.e.alert) and implement the methodalertView:clickedButtonAtIndex:.Let’s assume that you want the current class to be the delegate of the UIAlertView. You would use the following line of code:
Next, you would setup the current class to implement the
UIAlertViewDelegateprotocol in the .h file. For example:Then you would simply implement the
alertView:clickedButtonAtIndex:method in the .m file: