How to get the name of the selected UIActionSheet button in the shortcut?

I have a button with some options.

- (IBAction)monstrarActionSheet:(id)sender { UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"Titulo" delegate:self cancelButtonTitle:@"Mejor no" destructiveButtonTitle:@"Que miedo" otherButtonTitles:@"Otro boton 1", @"Otro boton 2", nil]; [action showInView: self.view]; 

When an option is selected, I display a message in the logs to show which button was selected.

 -(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ /*if(actionSheet.tag == 1){ }*/ NSLog(@"El usuario seleciono el boton %ld", (long)buttonIndex); } 

And in my ViewController.h my button and label are defined as

 @interface ViewController : UIViewController <UIActionSheetDelegate> @property (weak, nonatomic) IBOutlet UILabel *lbViewController1; 

How can I put the selected UIActionSheet button UIActionSheet in the lbViewController1 label?

+6
source share
1 answer

UIActionSheet deprecated, so you should use the UIAlertController for an action sheet of type for iOS 8.0+, but to answer your question using your current code, you can set the label to contain the button title like this:

 -(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ /*if(actionSheet.tag == 1){ }*/ NSLog(@"El usuario seleciono el boton %ld", (long)buttonIndex); self.lbViewController1.text = [actionSheet buttonTitleAtIndex:buttonIndex]; } 
+14
source

Source: https://habr.com/ru/post/982656/


All Articles