Now the key step is to specify which button is the cancel button, like:

alert.cancelButtonIndex = [titles count];

We do [titles count] and not [titles count] - 1 because we are adding the cancel button as extra from the list of buttons in titles.

You now also specify which button you want to be the destructive button (ie the red button) by specifying the destructiveButtonIndex (typically that will be the [titles count] - 1 button). Also, if you keep the cancel button to be the last button, iOS will add that nice spacing between the other buttons and the cancel button.

@MicahHainline - just add this line at the end of the 'for' loop: [actionSheet addButtonWithTitle:@"Cancel_Button_Title"]; actionSheet.cancelButtonIndex = actionSheet.numberOfButtons-1;
–
SagiftwMar 18 '12 at 18:26

This adds the buttons under the cancel button for me.
–
jspoonerApr 12 '12 at 2:12

I know this is an old post, but in case someone else, like me, is trying to figure this out.

(This WAS answered by @kokemomuke. This is mostly a more detailed explanation. Also building on @Ephraim and @Simon)

It turns out the LAST entry of addButtonWithTitle: needs to be the Cancel button. I'd use:

// All titles EXCLUDING Cancel button
for( NSString *title in titles)
[sheet addButtonWithTitle:title];
// The next two line MUST be set correctly:
// 1. Cancel button must be added as the last entry
// 2. Index of the Cancel button must be set to the last entry
[sheet addButtonWithTitle:@"Cancel"];
sheet.cancelButtonIndex = titles.count - 1;