我有這個代碼,當按下按鈕時加載一個新的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「 –
好的,給新代碼一個鏡頭。它提供了一個輕微的超時時間,以允許在賽段之間完成動畫。 – CocoaEv
呃,這很醜! (不是你的解決方案,但是繼續動畫會導致這個問題)。看起來最簡單和最乾淨的方法就是禁用動畫。謝謝,+1 :) – Jimmy