6

Flurry 分析を使用しているアプリ ストアにアプリがあります。そして、私が把握できない未処理の例外エラーが時々発生し続けます。

NSInvalidArgumentException: -[UIBarButtonItem setTintColor:]: 認識されないセレクターがインスタンス 0x177b20 に送信されました Msg: アプリケーションがクラッシュしました

私が理解できないのは、バーボタンアイテムの色合いをどこにも設定していないということです。右のバー ボタン項目を設定しているカスタム ビューがいくつかありますが、色合いはありません。

ボタンの私の使用のほとんどはこのように見えます。

- (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 つに色合いを設定していたことがわかりました。クラッシュを引き起こす可能性のあるOSバージョン間にいくつかの違いがあると思います。そのため、ナビゲーション バーにカスタムの右バー ボタン項目を設定する OS ニュートラルな方法を誰か教えていただければ幸いです。

4

3 に答える 3

7

問題は、2 つのクラスでの誤った -setTintColor の使用にありました。-setTintColor は 4.x デバイスではサポートされていないため、古いデバイスがティント カラーにぶつかるとクラッシュします。

于 2011-12-22T15:07:24.377 に答える
3

やってみました :

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

?

于 2011-12-17T15:04:41.407 に答える
1

ターゲットが iOS 4.0 の場合、これを行うことができます: AppDelegate.m の最後に @end の後に次のコードを入力します。

@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

この助けを願っています。私にとっては仕事です。

于 2011-12-17T16:21:19.853 に答える