3

iOS 5.1 を対象とする xcode 4.3 を使用しています。アプリのすべてのナビゲーション バーの右側にロゴを表示しようとしています。

最初に、すべてのビューコントローラーで次のコードを使用して機能させました

UIButton* fakeButton = (UIButton *) [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"driftlogo_header.png"]];
UIBarButtonItem *fakeButtonItem = [[UIBarButtonItem alloc] initWithCustomView:fakeButton];
self.navigationItem.rightBarButtonItem = fakeButtonItem;

これに関する問題は、すべてのビュー コントローラーでこれを行う必要があることですが、一部のビューは分類されていません。コードを減らしたいので、iOS 5 の外観プロパティを使用して、アプリ デリゲートからこれをグローバルに設定したいと考えていました。私はもう試した

UIButton* fakeButton = (UIButton *) [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"driftlogo_header.png"]];
UIBarButtonItem *fakeButtonItem = [[UIBarButtonItem alloc] initWithCustomView:fakeButton];
[[UIBarButtonItem appearance] setRightBarButtonItem:fakeButtonItem animated:YES];

機能しません。認識できないセレクターのエラーがインスタンスに送信されました。同じエラー

UIButton* fakeButton = (UIButton *) [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"driftlogo_header.png"]];
UIBarButtonItem *fakeButtonItem = [[UIBarButtonItem alloc] initWithCustomView:fakeButton];
[[UINavigationBar appearance] setRightBarButtonItem:fakeButtonItem];

アプリデリゲートからこれを設定する正しい方法は何ですか?

前もって感謝します。

4

0 に答える 0