我有这段代码在按下按钮时加载一个新的 UIView(来自情节提要)。goPressed 函数在按下按钮时触发,它调用 selectImage 函数。selectImage 打开一个 UIImagePickerController 并让用户选择一张照片。用户选择照片后,didFinishPickingMediaWithInfo 委托将所选图像添加到 UIImageView。
在“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 不起作用?我希望我没有遗漏您需要的任何信息。