好貼--iOS-關於UINavigationController的title不顯示問題

來源:互聯網
上載者:User

標籤:default   tab   更換   tail   art   而且   code   elf   cte   

用繼承自UINavigationController與UITabbarController 建立類,將前者設定為RootViewController,出現了一個問題,navigetionController的title不顯示,在controller裡面怎麼設定都不顯示,原因是這個樣子的:title這個屬性實際上是屬於UIViewController而不屬於UINavigationController。所以,這個屬性是從UIViewController上面繼承過來的。而不是UINavigationController上面的名字。由於UINavigationController屬於容器,所以最少需要一個RootController。然後在RootController的viewDidLoad設定title而不是在UINavigationController的subclass中設定。而且viewDidLoad設定的title是統一顯示的,導航視圖控制的UIViewController的title都是一樣的,我的解決方案是:將邏輯更換,UITabbarController設定為RootViewController,
 1 -(void)addTage:(Class)controller addName:(NSString *)name addImage:(NSString *)image addSelectImage:(NSString *)selectImage 2  3 { 4  5      6  7     UIViewController *vc = [[controller alloc] init]; 8  9     UINavigationController *cityNav = [[UINavigationControlleralloc]initWithRootViewController:vc];10 11     cityNav.tabBarItem.image = [UIImage imageNamed:image];12 13     cityNav.tabBarItem.selectedImage = [UIImage imageNamed:selectImage];14 15     cityNav.navigationBar.backgroundColor = [UIColor blueColor];16 17     cityNav.tabBarItem.title = name;18 19     cityNav.navigationBar.barStyle = UIBarStyleDefault;20 21     cityNav.navigationBar.barTintColor = [UIColor cyanColor];22 23     [self.navArray addObject:cityNav];24 25     26 27 }28 29  30 31     self.tabBarController.viewControllers = self.navArray;32 33  34     self.window.rootViewController = self.tabBarController;

 

好貼--iOS-關於UINavigationController的title不顯示問題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.