我正在编写一个 iOS 应用程序,其中的 View 中有一个按钮。单击该按钮会得到一个操作表,其中包含从相机或图库中选择图像的选项。选取图像后,应通过手动调用 segue 将其传递到另一个 View 。出现图像选择器并执行 segue 准备代码,但没有出现 segue。没有错误,我已经检查了所有标识符等。这是代码:
-(IBAction)showButtonClicked:(id)sender {
UIActionSheet *photoActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo", @"Choose from Library", nil];
photoActionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[photoActionSheet showInView:self.tabBarController.tabBar];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:
{
[self dismissModalViewControllerAnimated:YES];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
break;
}
case 1:
{
[self dismissModalViewControllerAnimated:YES];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
break;
}
default:
break;
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"goToPhotoDetails"]){
FostoPhotoDetailsViewController *photoDetails = (FostoPhotoDetailsViewController *)segue.destinationViewController;
photoDetails.imageView.image = self.buttonImage1;
}
}
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
self.buttonImage1 = image;
//FostoPhotoDetailsViewController *photoDetails = [[FostoPhotoDetailsViewController alloc] init];
//photoDetails.imageView.image = image;
[self dismissModalViewControllerAnimated:NO];
NSLog(@"Test");
[self performSegueWithIdentifier:@"goToPhotoDetails" sender:self];
}
最佳答案
听起来你正在执行风格为 push
的 segue不在UINavigationController
里面.
当您调用 performSegueWithIdentifier:sender:
时它首先正确调用 prepareForSegue:sender:
然后它会尝试检索当前的导航 Controller 并插入目标 Controller 执行类似
[self.navigationController pushViewController:destinationController animated:YES];
但是因为你不在 UINavigationController
里面属性(property)navigationController
设置为 nil
,导致上述调用静默失败。
要么将您的 segue 的显示样式更改为 push
以外的样式(例如 modal
)或将您的 Controller 嵌入 UINavigationController
.
关于objective-c - Segue 未出现在图像选择器之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13696145/