IOS 开发学习十六 UIActionSheet的使用

1.修改头文件,

@interface WasherFunsContentViewController : UIViewController<UIActionSheetDelegate>{
    
}

2.事件:

- (IBAction)showSheet:(id)sender {
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"title,nil时不显示"
                                  delegate:self
                                  cancelButtonTitle:@"取消"
                                  destructiveButtonTitle:@"确定"
                                  otherButtonTitles:@"第一项", @"第二项",nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;//黑底白字 
                                   // UIActionSheetStyleBlackTranslucent透明底白字 
                                   // UIActionSheetStyleDefault 灰底白字
    [actionSheet showInView:self.view];
    //使用Toolbar时,代码像下面这样写
    //[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
    //[sheet showInView:[AppDelegate sharedDelegate].tabBarController.view]   
}

3.委托获取点击

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        NSLog(@"确定");
    }else if (buttonIndex == 1) {
        NSLog(@"第一项");
    }else if(buttonIndex == 2) {
        NSLog(@"第二项");
    }else if(buttonIndex == 3) {
        NSLog(@"取消");
    }
    
}
- (void)actionSheetCancel:(UIActionSheet *)actionSheet{
    NSLog(@"cancel");
}
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
    NSLog(@"didDismiss");
}
-(void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{
    NSLog(@"willDismiss");
}

你可能感兴趣的:(ios,delegate,interface,UIActionSheet)