
首先,在.h中添加UIActionSheetDelegate,然后,调用:
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"标题为空时不显示"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"确定"
otherButtonTitles:@"AAA", @"BBB",nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:self.view];
再然后,重写代理:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"%ld",buttonIndex);
if (buttonIndex == 0) {
NSLog(@"确定");
}elseif (buttonIndex == 1) {
NSLog(@"AAA");
}elseif(buttonIndex == 2) {
NSLog(@"BBB");
}elseif(buttonIndex == 3) {
NSLog(@"取消");
}
}