iphone - How can I sent an array of strings into an UIActionSheet varargs init method? -


i have action sheet options vary depending on circumstances. there enough different button titles construct array of button titles first, can't figure out how convert varargs format.

i want this:

nsmutablearray *buttontitles = [nsmutablearray array]; if (condition1) {     [buttontitles addobject: @"do action 1"]; } if (condition2) {     [buttontitles addobject: @"do action 2"]; } if (condition3) {     [buttontitles addobject: @"do action 3"]; } if (condition4) {     [buttontitles addobject: @"do action 4"]; } uiactionsheet *actionsheet = [[[uiactionsheet alloc] initwithtitle: nil delegate: self cancelbuttontitle: @"cancel" destructivebuttontitle: nil otherbuttontitles: buttontitles] autorelease]; 

now if had instead:

uiactionsheet *actionsheet = nil; if (condition1 && condition2 && condition3 && condition4) {     actionsheet = [[[uiactionsheet alloc] initwithtitle: nil delegate: self cancelbuttontitle: @"cancel" destructivebuttontitle: nil otherbuttontitles: @"do action1", @"do action2", @"do action3", @"do action 4", nil] autorelease];     } else if (condition1 && condition2 && condition3 && !condition4) {     actionsheet = [[[uiactionsheet alloc] initwithtitle: nil delegate: self cancelbuttontitle: @"cancel" destructivebuttontitle: nil otherbuttontitles: @"do action1", @"do action2", @"do action3", nil] autorelease];     }  // else ... // 14 other cases! 

but horrible. know nice syntactic sugar me out?

edit: has been suggested use addbuttonwithtitle, on face of looks great, unfortunately puts additional buttons after cancel button, isn't desirable.

i believe bug apple's code since documentation on addbuttonwithtitle states:

// adds button title. returns index (0 based) of added. buttons displayed in order added except // destructive , cancel button positioned based on hi requirements. buttons cannot customized. 

hi requirements (apple's own human interface guidelines) favor cancel button below other options, i'd apple screwed up. of course, doesn't me, i'm trying convert between nsarray , varargs, still don't know how do.

you can try this

nsmutablearray *buttontitles = [nsmutablearray array]; if (condition1) {     [buttontitles addobject: @"do action 1"]; } if (condition2) {     [buttontitles addobject: @"do action 2"]; } if (condition3) {     [buttontitles addobject: @"do action 3"]; } if (condition4) {     [buttontitles addobject: @"do action 4"]; } [buttontitles addobject: @"cancel"]; uiactionsheet *actionsheet = [[[uiactionsheet alloc] initwithtitle: nil delegate: self cancelbuttontitle: nil destructivebuttontitle: nil otherbuttontitles: nil] autorelease];  (nsstring *title in buttontitles) {     [actionsheet addbuttonwithtitle: title]; }  [actionsheet setcancelbuttonindex: [buttontitles count] - 1]; 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -