Fill the action table with an array

I got an Actionheet popup in my iphone application. I would like to fill it with strings from an array instead of predefined values.

I can not find anything online to do this! Perhaps the action plan is not suitable for use?

Now this is what I use to create it:

roomspopup = [ [ UIActionSheet alloc ]  
                  initWithTitle: alertname  
                  delegate: self 
                  cancelButtonTitle: @"Cancel" 
                  destructiveButtonTitle: nil 
                  otherButtonTitles: @"Kitchen", "Dining Room", nil ];

But instead of "Kitchen" and "Canteen" I would like it to be filled from an array. The size of the array (i.e. the number of rooms) is not a fixed number.

+5
source share
3 answers

You cannot do this on one line. You will need to call initWithTitlewith an empty set of buttons, and then add other buttons with addButtonWithTitle:.

+7

@JimTrell

, UIActionSheet .

nil's:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose" 
                        delegate:self
                        cancelButtonTitle:nil
                        destructiveButtonTitle:nil
                        otherButtonTitles:nil];

addButtonWithTitle: , , :

[actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet setCancelButtonIndex:[yourArray count]];
+14

I can configure the cancel button below using this code:

anActionSheet = [[UIActionSheet alloc] initWithTitle:@"Change A/C" delegate:self
  cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil];

for (int i = 0; i < [arraylist count]; i++)    
  [anActionSheet addButtonWithTitle:[arraylist objectAtIndex:i]];

anActionSheet.cancelButtonIndex = [arraylist count];    
[anActionSheet addButtonWithTitle:@"Cancel"];
0
source

All Articles