2011-12-17 20 views
6

我在應用商店中有一個應用程序,我正在使用Flurry分析。我不時得到一個未處理的異常錯誤,我無法弄清楚。在UIBarButtonItem上發送無法識別的選擇器setTintColor

NSInvalidArgumentException: - [的UIBarButtonItem setTintColor:]:無法識別的選擇發送到實例0x177b20 消息:應用程序崩潰

我想不通是什麼,我沒有設置任何欄按鈕項目色彩隨處可見。我有幾個自定義視圖,我正在設置正確的欄按鈕項目,但沒有色調。

按鈕的大部分用法如下所示。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UINavigationBar *bar = [self.navigationController navigationBar]; 
    [bar setTintColor:[UIColor colorWithRed:0 green:69.0/255 blue:118.0/255 alpha:1]]; 
    self.navigationItem.title = @"Edit User"; 

    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] 
            initWithTitle:@"Save" 
            style:UIBarButtonItemStylePlain 
            target:self 
            action:@selector(editUser:)]; 
    self.navigationItem.rightBarButtonItem = saveButton; 
    [saveButton release]; 

    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] 
            initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 
            target:self 
            action:@selector(cancel)]; 

    [[self navigationItem] setLeftBarButtonItem:cancelButton]; 
    [cancelButton release]; 

} 

如果有人對此問題有任何意見,我將非常感激。我的目標是iOS 4.0,並在我的項目中。

更新: 我想出了導致setTintColor的一些隨機問題的原因。我發現我在其中一個實際的條形按鈕項目上設置了色調顏色。我猜測操作系統版本之間可能會導致崩潰。因此,如果任何人都可以告訴我一個操作系統中立的方式來設置我的導航欄中的自定義右鍵按鈕項目,將不勝感激。

+1

我最近遇到了一些問題。有時候,你必須在NavigationController的子視圖上調用setTintColor。 ([[[[self.navigationController.navigationBar subviews] objectAtIndex:1] setTintColor:[UIColor redColor]];)至少可以解決它。 – CodaFi

回答

7

問題在於2類上的errant -setTintColor用法。 -setTintColor在4.x設備上不受支持,所以當舊設備遇到色調顏色時會崩潰。

+0

我還發現''TintColor'不支持IOS 5.0及以下版本的'MPVolumeView'。 – ForceMagic

3

你試過:

self.navigationController.navigationBar.tintColor =[UIColor colorWithRed:0 green:69.0/255 blue:118.0/255 alpha:1]; 

?到底 在你AppDelegate.m @end把這段代碼後:

+0

聽起來更像是評論而不是答案。 – Till

+0

不,我似乎無法在模擬器或我的設備上覆制問題。我會嘗試一下並讓你知道。 –

1

,如果你的目標是iOS的4.0你可以做到這一點

@implementation UINavigationBar (UINavigationBarCategory) 
- (void)drawRect:(CGRect)rect { 
    UIColor *color = [UIColor YOUR_COLOR]; 
    self.tintColor = color; 
     //if you want image for background use this code 
    UIImage *img = [UIImage imageNamed: @"IMAGE_NAME.png"]; 
    [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
} 

@end 

希望這有助於。對我來說這是工作。

相關問題