Note that there are some explanatory texts on larger screens.

plurals
  1. POObj-C Switch Statement Integer Variable iPhone
    text
    copied!<p>I'm trying to use a switch statement to read out what button has been clicked in a UIActionSheet (programming for iPhone). </p> <p>The following is in my FirstViewController.m:</p> <pre><code> - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { int countarray=[areaselectArray count]; switch (buttonIndex) { case countarray: //cancel button has been pressed //do stuff break; default: area = [areaselectArray objectAtIndex:(buttonIndex)]; [[NSUserDefaults standardUserDefaults] setObject:area forKey:@"mulValue"]; [areaselectArray release]; NSLog(@"Released areaselectArray"); break; } } </code></pre> <p>The buttons for the UIActionSheet are built from an array that I built earlier (and have not yet released). I'm placing my Cancel button at the end of the list by using </p> <pre><code>int countarray=[areaselectArray count]; [areaselect.cancelButtonIndex = countarray;] </code></pre> <p>earlier on when allocating my UIActionSheet. Since the amount of buttons changes depending on the amount of entries in the array, I'd like the "Cancel" button to simply dismiss the UIActionSheet, but in all other instances have the Switch statement write the value of the clicked button to "mulValue" in standardUserDefaults.</p> <p>Is there any way to do this? My main issue right now of course is that a switch function won't take a variable (like countarray in my example). Is there any way to write the value to a constant (?) before entering the switch statement?</p> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload