I’m writing my own custom alert view for an application. The customer has their own look/feel for alert type messages. I’ve read that subclassing UIAlertView isn’t really a good idea, so I’m just trying to make the current message view I’m using a bit more dynamic so I can reuse it a bit more.
Ok, my question. I am stealing the init from UIAlertView to init my own custom alert.
- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
This was taken right out of Apple’s UIAlertView initializer. Mine is going to work just the same, so why not just use their init.
I want to be able to pass in multiple strings for otherButtonTitles, much like UIAlertView. My question is, how do I access the strings being passed in?
I would may the
otherButtonTitlesargument a NSArray instead of an NSString. From there you can dynamically generate additional buttons based on the count of the array, and set the title of said button to the NSString stored in current index of the array.EDIT: I think I’ve found something promising, in UIAlertView.m (not sure if it’s actually from Apple) but it takes otherButtonTitles as a string as well. It uses a
va_listto store the otherButtonTitles, and then add’s the objects to a mutable array that contains all the buttons, including the cancel button at index 0 (if applicable).https://github.com/BigZaphod/Chameleon/blob/master/UIKit/Classes/UIAlertView.m
Here’s an excerpt: