1

我正在编写一个 iOS 应用程序,其中视图中有一个按钮。单击该按钮会获得一个操作表,其中包含从相机或图库中选择图像的选项。选择图像后,应通过手动调用 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];
}
4

1 回答 1

2

听起来您正在执行带有风格的 seguepush而不是在UINavigationController.

当您performSegueWithIdentifier:sender:首先正确调用prepareForSegue:sender:它时,它会尝试检索当前导航控制器并推动目标控制器执行类似的操作

[self.navigationController pushViewController:destinationController animated:YES];

但是由于您不在 a 内部,UINavigationController因此该属性navigationController设置为nil,导致上述调用静默失败。

要么将 segue 的显示样式更改为push(例如modal)以外的其他内容,要么将控制器嵌入到UINavigationController.

于 2012-12-04T05:22:37.333 回答