Segue没有出现在Image Picker之后

时间:2012-12-04 04:34:21

标签: objective-c ios ios5 uistoryboard uistoryboardsegue

我正在编写一个iOS应用程序,在视图中有一个按钮。单击该按钮可获得一个操作表,其中包含从相机或图库中选择图像的选项。拾取图像后,应通过手动调用segue将其传递到另一个视图。出现图像选择器并执行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];
}

1 个答案:

答案 0 :(得分:2)

听起来你正在执行一个样式为push的segue而不在UINavigationController内。

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

的操作
[self.navigationController pushViewController:destinationController animated:YES];

但由于您不在UINavigationController内,因此navigationController属性设置为nil,导致上述调用无声地失败。

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