UIActionSheet event not firing

寵の児 提交于 2019-12-04 05:47:16

问题


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!


回答1:


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;



回答2:


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!



来源:https://stackoverflow.com/questions/19959101/uiactionsheet-event-not-firing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!