標籤:
1 // 2 // ViewController.m 3 // UIActionSheet詳解 4 // 5 // Created by 大歡 on 16/1/25. 6 // Copyright © 2016年 bjsxt. All rights reserved. 7 // 8 9 #import "ViewController.h"10 11 @interface ViewController ()<UIActionSheetDelegate>12 13 - (IBAction)showActionSheet:(id)sender;14 15 @end16 17 @implementation ViewController18 19 - (void)viewDidLoad {20 [super viewDidLoad];21 22 }23 24 - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {25 26 switch (buttonIndex) {27 case 0:28 NSLog(@"確定");29 break;30 case 1:31 NSLog(@"可以");32 break;33 case 2:34 NSLog(@"取消");35 break;36 default:37 break;38 }39 40 }41 42 - (IBAction)showActionSheet:(id)sender {43 44 UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle:@"題目" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"確定" otherButtonTitles:@"可以", nil];45 46 [sheet showInView:self.view];47 48 [self performSelector:@selector(dismissActionSheet:) withObject:sheet afterDelay:5];49 50 }51 52 - (void)dismissActionSheet:(UIActionSheet *)sheet {53 54 [sheet dismissWithClickedButtonIndex:0 animated:YES];55 }56 57 58 @end
iOS學習-UIActionSheet詳解