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