简体   繁体   English

如何在UINavigationController中使用UIImagePickerController

[英]How to use a UIImagePickerController with UINavigationController

I've browsed the different similar questions here but couldn't find anything useful for my problem. 我在这里浏览了其他类似的问题,但找不到对我的问题有用的任何东西。 What I'm struggling with is quite simple but I can't figure it out. 我正在努力的事情很简单,但我无法弄清楚。

I'm using Xcode 4.6.2 and Storyboarding. 我正在使用Xcode 4.6.2和Storyboarding。 Here is the storyboard: 这是情节提要: 在此处输入图片说明

Here is the workflow I'd like to have: 这是我想要的工作流程:

  • Taping on a cell in the tableVC should push the Edit document view and offer the Back and Done buttons. 轻击tableVC中的单元格应按“编辑文档”视图,并提供“上一步”和“完成”按钮。
  • Taping on the camera picture should "load" (push/modal?) my cameraVC which is a subclass of UIImagePickerController. 拍摄相机图片时应“加载”(按/模态?)我的cameraVC,它是UIImagePickerController的子类。 I've added a custom overlay on top of the picker and use a custom button to take picture. 我在选择器顶部添加了自定义叠加层,并使用自定义按钮拍照。 On this event I currently perform the segue leading to the previewDocumentView (modally presented) and when the "Use" button is tapped I present the Edit document view. 当前,在此事件上,我执行引导到PreviewDocumentView(以模式方式显示)的搜索,并在轻按“使用”按钮时显示编辑文档视图。

Problem is the Edit document view does not have the navigation bar even if I try to set the property self.navigationBarHidden = NO; 问题是,即使我尝试设置属性self.navigationBarHidden = NO;编辑文档视图也没有导航栏self.navigationBarHidden = NO; This seems normal to me though since I've presented the views modally but how to do it then? 虽然这对我来说似乎很正常,因为我已经以模态方式呈现了视图,但是那怎么办呢?

I tried pushing my cameraVC from the tableVC but I get an error saying that stacking 2 navigationControllers is prohibited (since cameraVC subclass of UIImagePickerController subclass of UINavigationController). 我尝试从tableVC推送我的cameraVC,但是收到一条错误消息,提示禁止堆叠2个navigationControllers(因为UINavigationController的UIImagePickerController子类的cameraVC子类)。 It seems that my only option is to present the cameraVC modally but then I don't know how to present the Edit document VC with its navigation bar. 看来,我唯一的选择是模态显示cameraVC,但随后我不知道如何使用其导航栏显示“编辑”文档VC。

EDIT : Having a navigation bar in the cameraVC is not optimal but is acceptable if this is the only way of doing it. 编辑 :cameraVC中的导航栏不是最佳选择,但如果这是唯一的方法,则可以接受。

It would appear that the best solution is to use an unwind segue! 似乎最好的解决方案是使用轻松的搜索!

In summary: 综上所述:

1)In the tableVC create a method such as 1)在tableVC中创建一个方法如

- (IBAction)unwindToThisViewController:(UIStoryboardSegue *)unwindSegue
{
    NSLog(@"Rolled back");
}

2)Create an unwind segue for your previewDocumentVC and give it a unique ID such as "unwindFromPreview", connecting it to the unwindToThisViewController IBAction. 2)为您的PreviewDocumentVC创建一个展开序列,并为其指定一个唯一的ID,例如“ unwindFromPreview”,并将其连接到unwindToThisViewController IBAction。 Check this answer I gave in the past for the detailed steps on how to achieve this (steps 2 and 3). 检查一下我过去给出的答案 ,以获取有关如何实现此步骤的详细步骤(步骤2和3)。

3)Create a prepareForSegue method in your previewDocumentVC where you set some tableVC BOOL property, such as 3)在previewDocumentVC中创建一个prepareForSegue方法,在其中设置一些tableVC BOOL属性,例如

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"unwindFromPreview"]) {
        ((TableVC*)segue.destinationViewController).shouldTransitionToEditDocVC = YES;
    }
}

4) In your tableVC's ViewWillAppear method you then check the shouldTransitionToEditDocVC and if it is set to YES you perform the segue to the editDocVC. 4)然后在tableVC的ViewWillAppear方法中,检查shouldTransitionToEditDocVC ,如果将其设置为YES,则对editDocVC进行选择。

I hope this helps! 我希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM