加入代理
@interface ImagePickeriewController ()<UIActionSheetDelegate>
@end
添加button的点击响应,响应事件中代码如下
-(void) photoImageClicked{
UIActionSheet *photoSheet;
photoSheet = [[UIActionSheet alloc] initWithTitle:@"选择" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"从相册选择", nil];
photoSheet.tag = 255;
[photoSheet showInView:_photoView];
}
delegate
-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if(actionSheet.tag == 255){
if (buttonIndex == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"拍照" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:NULL];
[alert show];
}else if (buttonIndex == 1){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"从相册选择" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:NULL];
[alert show];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"取消" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:NULL];
[alert show];
}
}
}