2016-01-22 134 views
0

经过大量研究后,我认为我发现问题出现在我的应用程序中,但找不到解决方案。UITabBar在UIImagePickerController模式消失后消失

在我的项目中,如截图所示,我有一个UITabBarController作为初始视图控制器。 UINavigationController将“显示(推送)”以显示UIViewController。在我的UIViewController里面,我会打电话UIImagePickerController,这是由XCode设置在“Modal”上。

问题出现了,当我解雇UIImagePickerController时,UITabBar项目消失。我知道这与解除模态有关,但我找不到解决方案。

enter image description here

我的代码如下:

上的一个按钮的点击里面UIViewController

@IBAction func chooseLibrary(sender: AnyObject) { 

    let picker = UIImagePickerController() 
    picker.delegate = self 
    picker.sourceType = .PhotoLibrary 
    picker.allowsEditing = true 

    self.navigationController?.presentViewController(picker, animated: true, completion: nil) 
} 

上的 “取消” 点击里面UIImagePickerController

func imagePickerControllerDidCancel(picker: UIImagePickerController) { 
    self.navigationController?.dismissViewControllerAnimated(true, completion: nil) 
} 
+0

为什么不使用self.presentViewController(picker,animated:true,completion:nil)? – jansma

+0

物品消失或标签栏本身消失吗? – beyowulf

+0

这是我第二次发布这个问题,并基于其他评论,他们说使用'self.navigationController?.presentViewController'。但是,无论哪种方式都行不通。 – jo3birdtalk

回答

0

试试这个:

@IBAction func chooseLibrary(sender: AnyObject) { 

    let picker = UIImagePickerController() 
    picker.delegate = self 
    picker.sourceType = .PhotoLibrary 
    picker.allowsEditing = true 

    self.navigationController?.pushViewController(picker, animated: true) 
} 

func imagePickerControllerDidCancel(picker: UIImagePickerController) { 
    self.navigationController?.popViewControllerAnimated(true) 
} 
+0

'UIImagePickerController'是一个模式当下。而'popViewControllerAnimated'用于推送。我也试过了,但它不起作用。 – jo3birdtalk

0

设置viewController.hidesBottomBarWhenPushed = NO;对于所有想要显示标签栏的控制器。 当您推/视您的视图控制器时,必须设置此标志。 希望这会解决你的问题。

+0

嗨,hidesBottomBarWhenPushed用于显示或推送,而不是模态。由于UIImagePickerController是一种模式,因此hidesBottomBarWhenPushed将不起作用。 – jo3birdtalk

+0

@ jo3birdtalk是的,“hidesBottomBarWhenPushed”不适用于模态。你知道如何在呈现模态时隐藏“bottomBar”吗? – AziCode