2017-05-07 88 views
0

我遇到了一個非常尷尬的自動佈局問題。我有一個導航控制器,爲了某種目的,我將它的rootviewcontroller設置爲tabbarview控制器。見圖像波紋管:與TabBarController的AutoLayout問題

enter image description here

在上述圖像可以看到有6的ViewController與tabbarviewcontroller連接。

  • 在第三第四第五和第六的ViewController白色視圖添加和自動佈局下面給出:現在

enter image description here

,運行後,當我選擇選項卡3或4,加入的視圖根據自己的需要顯示完美,並根據自動佈局顯示它應該顯示。即如下: enter image description here enter image description here

現在,當我選擇,因爲它應該根據它的默認行爲「更多」,那麼它呈現出tableviewcontroller,在下面給出:

enter image description here

這裏是問題發生了,現在如果從列表中選擇任何項目並轉到相關的視圖控制器,則添加的白色視圖將從導航欄中刪除。我不明白爲什麼會發生這種情況。請參閱在PIC:

enter image description here enter image description here

整整一天我曾試圖解決這個問題,但沒有任何反應,有些是如何得到一個解決方案,但它是我需要的不是在這裏。即見圖片如下:

enter image description here

如果取消選中「在熱門酒吧」該視圖控制器,然後它的作品很好,但它影響了導航欄,我這裏不想要的。請參閱圖像:

enter image description here

能有人在這裏誰也面臨着類似的問題,並找到了一個完美的解決方案,我尋求幫助。

注意:在任何視圖控制器中都沒有采用任何類,所有視圖都在故事板中。

在此先感謝。

+0

做禁用**調整viewController的滾動視圖插入**。 – KKRocks

+0

@KKRocks做到了,沒有工作。 –

+0

UINavigationBar.appearance()。appdelegate中的translucent = false試試這個 – KKRocks

回答

1

這是問題是有兩個導航欄....你可以跟蹤視圖層次.....你能解釋一下我你想要什麼?

+0

是的,一些我需要一個單一的導航欄與rootviewcontroller tabbarcontroller,現在如果在該tabbarcontroller添加5個viewcontrollers,並添加子視圖通過故事板查看,它適用於所有5視圖控制器,但作爲我添加一個更多的視圖控制器,第五視圖控制器和第六視圖控制器來一個tableview,這很好,但是當我從表視圖選擇任何viewcontroller那麼添加子視圖就會下降。可能它正在發生什麼你的答案,我幾乎肯定它確實是由於兩個導航控制器,但現在得到它的騎... ..? –

+0

在storyboard中檢查您的viewcontroller ....嘗試刪除該導航控制器。 – KKRocks

+0

但是我必須保留這個爲我的真實項目。 –

0

拿了UiTbaBarControllerClass我tabbarcontroller並在該控制器我設置委託自我,並按照我的代碼,現在它的工作,我想。非常感謝@KKRocks

代碼:

#import "TabBarController.h" 

    @interface TabBarController()<UITabBarControllerDelegate> 

    @end 

    @implementation TabBarController 

    - (void)viewDidLoad { 
     [super viewDidLoad]; 
     // Do any additional setup after loading the view. 

     self.delegate = self; 
    } 

#pragma mark UITabBarController Delegate 

    - (void)tabBarController:(UITabBarController *)tabBarController 
    didSelectViewController:(UIViewController *)viewController 
    { 
     NSLog(@"controller class: %@", NSStringFromClass([viewController class])); 
     NSLog(@"controller title: %@", viewController.title); 

     if ([viewController.title isEqual:@"More"]) { 

      [self.navigationController setNavigationBarHidden: YES animated: NO]; 
     } 
    } 

而且在斯威夫特

class TabBarController: UITabBarController, UITabBarControllerDelegate { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view. 
     self.delegate = self 
    } 

// MARK: UITabBarController Delegate 

    func tabBarController(_ tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) { 

     print("controller class: \(String(describing: viewController.self))") 

     print("controller title: \(String(describing: viewController.title))") 

     if viewController.title?.isEqual("More") { 

      navigationController?.setNavigationBarHidden(true, animated: false) 
     } 
    } 
} 

現在的工作很細。 :)