Reputation: 6347
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!
Upvotes: 0
Views: 270
Reputation: 20410
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;
Upvotes: 4
Reputation: 2147
It looks like you have forgotten to set the delegate. You need to implement UIActionSheetDelegate
(which it looks like you have) and then set the delegate!
Upvotes: 3