我正在构建这个应用程序并且非常成功。但是,我最近想改变用户选择上传图片的方式。它现在有一个动作表。问题是,当单击一个按钮时,我尝试关闭动作表,然后启动图像库,但它不起作用。谢谢你的帮助!
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
[actionSheet dismissWithClickedButtonIndex:0 animated:NO];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:NULL];
}
///////////
UIActionSheet *actionsheet = [[UIActionSheet alloc]
initWithTitle:@"Submit Photo"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Take Photo",@"Select Photo from Gallery", nil];
[actionsheet showInView:self.view];
答案 0 :(得分:1)
不是实现actionSheet:clickedButtonAtIndex:
委托方法,而是实现actionSheet:didDismissWithButtonIndex:
方法。然后你不需要自己解雇行动表。
确保在创建时将self
作为代理传递给操作表。