ボタンを押したときに新しいUIView(ストーリーボードから)をロードするこのコードがあります。 goPressed関数は、押されたボタンで起動され、selectImage関数を呼び出します。 selectImageはUIImagePickerControllerを開き、ユーザーが写真を選択できるようにします。ユーザーが写真を選択すると、didFinishPickingMediaWithInfoデリゲートが選択したイメージをUIImageViewに追加します。performSegueWithIdentifierが動作しない
'goPressed'では、selectImageが実行された後、// 1と同様のコメントでSegueを実行するはずです。しかし、何も起こりません。 performSegueWithIdentifierが機能していないようです。私はperformSegueWithIdentifierを呼び出す前に[self selectImage]を呼び出さないと動作します。コードは次のとおりです。
- (IBAction)goPressed:(id)sender {
[self selectImage];
[self performSegueWithIdentifier:@"lastView" sender:currentSender]; //1
}
-(void)selectImage
{
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// Delegate is self
imagePicker.delegate = (id)self;
// Allow editing of image ?
imagePicker.allowsEditing=NO;
// Show image picker
[self presentModalViewController:imagePicker animated:YES];
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[[picker presentingViewController] dismissModalViewControllerAnimated:YES];
lePreview.image= image;
}
performSegueWithIdentifierが機能しない理由を教えてください。あなたが必要とする情報が不足していないことを願っています。
あなたは、私がdismissModalViewControllerAnimatedを設定したときにそれは動作しますが、私のポイントを得た:NO ...しかし、私はアニメーションを維持するためにあなたのコードを使用している場合、XCodeのは、私は、このエラーを与える:インスタンスメッセージの 」のUIViewは、セレクタでメソッドを宣言しませんdismissmodalviewcontrolleranimated:completion " –
ok、新しいコードを打ち込みましょう。これは、アニメーションがセグの間で完了できるようにわずかなタイムアウトを提供します。 – CocoaEv
ああ、これは醜いです! (あなたの解決策ではなく、segueアニメーションがこの問題を引き起こす方法)。最も簡単でクリーンな方法は、単にアニメーションを無効にすることです。ありがとう、+1 :) – Jimmy