I have an actionsheet popup in my iphone application. I would like to fill it with strings from an array instead of predetermined values.
I can't find anything online to do this! Perhaps actionsheet isn't the right thing to use?
Right now this is what I'm using to build it:
roomspopup = [ [ UIActionSheet alloc ]
initWithTitle: alertname
delegate: self
cancelButtonTitle: @"Cancel"
destructiveButtonTitle: nil
otherButtonTitles: @"Kitchen", "Dining Room", nil ];
But, instead of "Kitchen" and "Dining Room" I'd like it to fill in from an array. The size of the array (i.e. the number of rooms) is not a fixed number.
@JimTrell
The way to fix that would be to init the UIActionSheet without the cancel button and add this cancel button after you added your other buttons.
First init the sheet with a bunch of nil's:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
Then loop through your array with addButtonWithTitle:
and finally add the cancel button and set its index:
[actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet setCancelButtonIndex:[yourArray count]];
You can't do it in one line. You'll have to call initWithTitle
with an empty set of buttons, and then add your other buttons with loop using addButtonWithTitle:
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With