
1.在当前的视图头文件添加协议 UIActionSheetDelegate
如:
@interface DebbieViewController : UIViewController<UIActionSheetDelegate>
2.在当前的视图的DebbieViewController.m文件中实现协议<UIActionSheetDelegate>的方法;
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"you click buttonIndex is :%d",buttonIndex); }
3.通过按键当前的视图的button按钮 显示actionsheet ;
-(void)clickbutton{ UIActionSheet *action=[[UIActionSheet alloc] initWithTitle:@"this is title" delegate:self cancelButtonTitle:@"cancelbutton" destructiveButtonTitle:@"surebutton" otherButtonTitles:@"otherbutton 3",@"otherbutton4", nil]; //显示action sheet ;设置一个parent 这个parent必须是view,并且是当前的视图 [action showInView:self.view]; }
浙公网安备 33010602011771号