objective-c - Segue 未出现在图像选择器之后

标签 objective-c ios ios5 uistoryboard uistoryboardsegue

我正在编写一个 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/

相关文章:

iOS 框架问题 : Class is implemented in both

objective-c - UISearchDisplayController 显示未过滤的数据

iphone - 获取图像索引

ios - 如何从后台(未运行)唤醒(或启动)我的应用程序? ios-ibeacon-iphone

animation - iOS5将CGAffineTransform与animationImages结合起来?

iphone - UISegmentedControl 放在 tableView 标题中时行为异常

iOS- 配置文件问题。

xcode - 错误 : Terminating app due to uncaught exception 'NSUnknownKeyException' , 原因:'[<UIApplication 0x6887a30> setValue:forUndefinedKey:]

iphone - 在 iOS 5 中以模态方式呈现来自委托(delegate)的 View

ios - 将数据插入 Core Data 并检查它是否已经存在