ユーザーが UIImagePicker を使用してギャラリーから画像を選択しているときに、「よろしいですか」ボタンを追加しようとしています。これが私が今しようとしている方法です。
これがUIImagePickerの提示方法です
{
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:YES completion:nil];
}
画像を選択すると、このメソッドが呼び出されます
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
myImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Do you want to set this image as your profile picture?"
delegate:self
cancelButtonTitle:@"No"
destructiveButtonTitle:@"Yes"
otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
[actionSheet showInView:[self.view window]];
}
次に、destructiveButton
が選択されている場合は、UIImagePicker を呼び出したビューに戻ります。
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == actionSheet.destructiveButtonIndex) {
[self dismissViewControllerAnimated:YES completion:nil];
}
問題は、この例外をスローしていることです
-[UIActionSheet showInView:]、/SourceCache/UIKit_Sim/UIKit-2903.2/UIActionSheet.m:5123 2013-10-10 22:14:55.735 Globism[1997:a0b] でのアサーションの失敗* キャッチされない例外 'NSInternalInconsistencyException' によるアプリの終了、理由: '無効なパラメーターを満たさない: ビュー != nil' *最初のスロー コール スタック:
私の推測では、それが関係していると思いますが、それを[actionSheet showInView:[self.view window]];
回避する方法がわかりません。誰かが私を正しい方向に向けることができますか? スニペットは本当に役に立ちます!ありがとう!