Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jeremy1026

macrumors 68020
Original poster
Nov 3, 2007
2,215
1,029
Ok, I created my UIActionSheet and populated it with 5 buttons. Now how do I determine which button is pressed (to continue on with the operation of my application)?

I tried using:
Code:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
	// the user clicked one of the OK/Cancel buttons
	if (buttonIndex == 0)
	{
		NSLog(@"ok");
	}
}

When I drop this into my application, NSLog doesn't show anything no matter what button I press?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Have you tried logging the buttonIndex to see what it gets set to? I'm sure the documentation tells you the values, but as I'm not on a Mac right now I can't tell you where.
 

Luke Redpath

macrumors 6502a
Nov 9, 2007
733
6
Colchester, UK
I seem to remember having this issue the other day when I used UIActionSheet for the first time - can't remember exactly what the issue was and I don't have my code nearby. However, it *might* be that you are trying to compare an NSNumber to an int. One thing that will work is to call [buttonIndex integerValue] and compare that to an int but there might be a more idiomatic way of doing this (look at the NSNumber documentation).
 

Luke Redpath

macrumors 6502a
Nov 9, 2007
733
6
Colchester, UK
Had a look at my own UIActionSheet delegate method and I'm using a switch statement:

Code:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
  switch (buttonIndex) {
    case 0:
       // do something
      break;
    case 1: 
       // do something else
    default:
      break;
  }
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.