2010-04-14 169 views
4

奇怪的問題:在將我的應用程序旋轉爲縱向後,選取工具欄項並顯示uipopovercontroller,如果我旋轉回橫向,右側的UINavigationController(SplitView的objectAtIndex:0)改變導航欄的顏色。我不知道爲什麼。我有它在界面生成器中設置爲barStyle = UIBarStyleBlackOpaque;iPad SplitView更改主導航欄顏色

回到風景模式後變成銀色。

這隻會發生,如果我把它旋轉到肖像,創建彈出窗口,並選擇導航控制器,推動另一個tableViewController的東西。即使在viewDidLoad方法中設置屬性也不會執行任何操作。

任何人有想法?

回答

7

viewDidLoad只會在第一次顯示您的視圖時被調用(或者由於內存問題而被清除)。嘗試重新設置viewWillAppear中的barStyle,甚至是 - splitViewController:willShowViewController:invalidatingBarButtonItem :.

+0

謝謝,工作!在viewWillAppear - self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; – Justin 2010-04-15 03:02:15

+2

請記住,在viewWillUnload或dealloc中,記得將IBOutlets設置爲零,以便在OS/Nav/Tabbar Controller決定卸載該視圖時啓用資源回收。沒有這一步,你就有可能在後期發生奇怪的內存泄漏。 – Jann 2010-04-15 04:11:40

+0

+1 Jann,人們總是忘記這一點。 – 2010-04-15 14:15:54

1

很酷,修復它。

添加到我的RootViewController的其中splitviewcontroller和導航欄聲明:

- (void)viewWillAppear:(BOOL)animated { 

    [super viewWillAppear:YES]; 


    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; 

} 
1

我有同樣的問題,但在viewWillAppear中重置barStyle導致另一個問題。當它在彈出窗口中顯示時設置它,所以它不再匹配彈出顏色。只有在分割視圖控制器的左窗格中顯示barStyle時,我如何才能將barStyle設置爲我想要的?我想我可以將它設置在視圖中,只有當方向是橫向時,纔會出現,但看起來很髒。此外,將其設置在splitViewController:willShowViewController:invalidatingBarButtonItem:根本不起作用,因爲我認爲這是在分割視圖控制器將樣式設置回默認值之前調用的。這在蘋果方面似乎是一個非常愚蠢的錯誤。它應該將它改回原來的樣式,而不是默認的樣式。

2

爲史蒂夫(檢測RootViewControll的PoPView或SPLITVIEW的導航欄)[SPLITVIEW IPAD]

宥必須創建一個類的方法(setLand:int i)以上RootViewController的這些方法從detailviewcontroller叫做:

- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem { 
    // LANDSCAPE !!!! 
    [RootViewController setLand:1]; 

- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc { 
    // PORTRAIT!! 
    [RootViewController setLand:0]; 

和RootViewController的:

static int landscape=2; 

    ... 

// SetMethod for class variable landscape 
     + (void)setLand:(int)i 
     { 
      if(landscape!=i){ 
       landscape = i; 

      } 
     } 

和RootViewController的

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
    if(landscape == 1) 
    { 
     //LANDSCAPE! 
     CUSTOM FOR LANDSCAPE 
     self.navigationController.navigationBar.barStyle =... 
    } 
    else if(landscape == 0) 
    { 
     //PORTRAIT! 
     CUSTOM FOR PORTRAIT 
     self.navigationController.navigationBar.barStyle =... 
    } 
    } 

..this在我的應用效果很好,編輯自定義的橫向/縱向的導航欄

2

有似乎是一個問題finaly送花兒給人4.2並在旋轉後設置導航條的tintColor。您可以使用上述答案正確設置barStyle,但不能使用tintColor。其他人有相同的問題?

+0

是的,我有同樣的問題,我會瘋了!在我的RootViewController viewWillAppear中,這兩行都不起作用: – PostCodeism 2010-12-08 17:19:06

+0

self.navigationBar.tintColor = [UIColor redColor]; – PostCodeism 2010-12-08 17:20:14

+0

[[[[splitViewController viewControllers] objectAtIndex:0] navigationBar] setTintColor:[UIColor redColor]]; – PostCodeism 2010-12-08 17:21:24

1

中解決此問題 用下面的代碼

@implementation ChangeNavigationBarColor 

- (void) setTintColor:(UIColor*)color 
{ 
    [super setTintColor:[[BrandingManager sharedBrandingManager] tintColorForNavigationController]]; 
} 


@interface ChangeNavigationBarColor : UINavigationBar { 

} 

@end 
2

@Brendan G. Lim和具有與該tintColor麻煩其他任何,終於得到了一個自定義導航欄的工作:

  1. 創建從UINavigationBar分類的自定義導航文件
@interface CustomNavigationBar : UINavigationBar 
{ 
} 

@end 
  1. 在實現文件中,覆蓋setTintColor方法
@implementation CustomNavigationBar 

-(void)setTintColor:(UIColor *)tintColor 
{ 
    [super setTintColor :[self tintColor]]; 
} 

@end 
  1. 開放的MainWindow.xib,並選擇您的導航欄要設置顏色爲。在你的Identity窗格[Apple] [4]中選擇CustomNavigationBar作爲類。

  2. 在屬性窗格[Apple] [1]中設置條的顏色。

就是這樣!

1

提交了一個關於本週前的錯誤報告,Apple表示這是一個已知的4.2錯誤。然後我問是否有辦法解決這個問題,但目前還沒有答覆。

用子類/自定義導航欄替換UINavigationbar也沒有用。 popover似乎在UINavigatioBar上執行了一些祕密的令人討厭的東西,它會殺死tintColor並且不允許重置它(即使在重置它之後它也將始終保持'零')。

我基本放棄了,並告訴客戶,他將不得不忍受它,直到下一次更新(希望)。

0

您可以使用單獨的類來更改顏色,使背景顏色爲類,所需顏色,然後將該類用作rootViewController的類。我做了,它的工作。