Search code examples
iosobjective-cuiactionsheet

UIActionSheet event not firing


I have a UIActionSheet to provide user options on a table view controller. I have implemented this before without issue, but for some reason now, my event handler does not fire when a button is clicked. In my header file, I have implemented the proper delegate as follows:

@interface GaugeDetailTableViewController : UITableViewController <UIActionSheetDelegate>

In my implementation, I have the following code to support the action sheet:

-(void)loadPopup{
UIActionSheet *popup = [[UIActionSheet alloc]
                        initWithTitle:@"Options"
                        delegate:nil
                        cancelButtonTitle:@"Cancel"
                        destructiveButtonTitle:nil
                        otherButtonTitles:@"Add to Favorites", @"Gauge Detail Help", @"Main Menu", nil];
popup.actionSheetStyle = UIActionSheetStyleDefault;

[popup showInView:self.view];
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"%d\n", buttonIndex);
}

The action sheet appears properly on the view controller, but for some reason, the action sheet click event handler is never reached. Any suggestions? Thanks!


Solution

  • You need to set the delegate:

    UIActionSheet *popup = [[UIActionSheet alloc]
                            initWithTitle:@"Options"
                            delegate:self
                            cancelButtonTitle:@"Cancel"
                            destructiveButtonTitle:nil
                            otherButtonTitles:@"Add to Favorites", @"Gauge Detail Help", @"Main Menu", nil];
    popup.actionSheetStyle = UIActionSheetStyleDefault;