UIActionSheet 彈出選擇按鈕項
阿新 • • 發佈:2019-02-05
加入代理
@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];
}
}
}