The Apple documentation on otherButtonTitles has this to say:
The title of another button.
Using this argument is equivalent to invokingaddButtonWithTitle:with this title to add more buttons.
| // Observed bug(?): When adding a button after creating UIAlertView, the firstOtherButtonIndex value | |
| // is stuck as -1 instead of the correct value, 1, even though the documentation states that the two | |
| // invocations below should be equivalent. | |
| NSString *closeText = @"Cancel"; | |
| NSString *actionText = @"OK"; | |
| UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title | |
| message:message | |
| delegate:self | |
| cancelButtonTitle:closeText | |
| otherButtonTitles:nil]; | |
| if (actionText) { | |
| [alertView addButtonWithTitle:actionText]; | |
| } | |
| NSLog(@"alertView cancel:%ld firstOther:%ld", (long)alertView.cancelButtonIndex, (long)alertView.firstOtherButtonIndex); | |
| // alertView cancel:0 firstOther:-1 | |
| UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title | |
| message:message | |
| delegate:self | |
| cancelButtonTitle:closeText | |
| otherButtonTitles:actionText, nil]; | |
| NSLog(@"alertView cancel:%ld firstOther:%ld", (long)alertView.cancelButtonIndex, (long)alertView.firstOtherButtonIndex); | |
| // alertView cancel:0 firstOther:1 |