2016-01-22 197 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