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

yaboy10holla

macrumors newbie
Original poster
Feb 19, 2011
17
0
Hi, I'm trying to test out some action sheet skills and I can't figure out why this isnt working. I'm trying to get the title of the action sheet button to simply post in a UITextField. here are my actions:


Code:
-(IBAction)doActionSheet:(id)sender {
	UIActionSheet *actionSheet;
	actionSheet=[[UIActionSheet alloc]initWithTitle:@"Available Actions"
										   delegate:nil 
								  cancelButtonTitle:@"Cancel" 
							 destructiveButtonTitle:@"Destroy" 
								  otherButtonTitles:@"Negotiate", @"Compromise", nil];
	[actionSheet showInView:self.view];
}

---------and then this -------------


Code:
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex {
	NSString *buttonTitle=[actionSheet buttonTitleAtIndex:buttonIndex];
	if ([buttonTitle isEqualToString:@"Destroy"]) {
		userOutput.text=@"Destroy";
	} else if ([buttonTitle isEqualToString:@"Negotiate"]) {
		userOutput.text=@"Negotiate";
	} else if ([buttonTitle isEqualToString:@"Compromise"]) {
		userOutput.text=@"Compromise";
	} else {
		userOutput.text=@"Cancel";
	}
}



I modified the controller header file to include the UIActionSheetDelegate protocol as well. So I'm not sure why nothing happens when you click the button.

any help greatly appreciated!! thanks
 
Last edited by a moderator:
This is what I do

Go to the .H file, do this -->

Code:
@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UIActionSheetDelegate>

Code:
 UIBarButtonItem *settingsBarButtonItem;
Code:
 @property (nonatomic, retain) IBOutlet UIBarButtonItem *settingsBarButtonItem;

.M file

Code:
@synthesize settingsBarButtonItem;

Code:
- (IBAction) changeToSettings:(id)sender {
	//NSLog(@"gets called changeToSettings");
	UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Account Settings"
															 delegate:self 
													cancelButtonTitle:nil 
											   destructiveButtonTitle:nil 
													otherButtonTitles:@"Setting 1", 
								  @"Setting 2", nil];
	[actionSheet showFromBarButtonItem:[self settingsBarButtonItem] animated:YES]; 
	[actionSheet release];   
}


Code:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
	
	switch (buttonIndex) {
		case 0:
			userOutput.text = @"Settings 1 clicked";
			break;
			
		case 1:
			userOutput.text = @"Settings 2 clicked"; 
			break;
			
		default:
			NSLog(@"default got called");
			break;
	}
}

Something like that I guess..
 
thanks guys really appreciate it. changed the delegate to self and now it works perfect!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.