应用程序崩溃时setBackButtonBackgroundImage

时间:2013-06-25 08:57:23

标签: ios objective-c uinavigationcontroller uinavigationbar

我正在尝试使用以下代码全局设置UINavigationBar的外观:

[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"bg_daohang"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackButtonBackgroundImage:[UIImage imageNamed:@"btn_fanhui_1"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

我成功设置了barStyle和backGroundImage,但是当我设置backButtonBack(第三行)的外观时。应用程序崩溃,我收到如下错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UIAppearance     setBackButtonBackgroundImage:forState:barMetrics:]: unrecognized selector sent to instance 0x1dd7ea00'

如何全局正确设置backButtonBack的外观?

1 个答案:

答案 0 :(得分:1)

setBackButtonTitlePositionAdjustment:forBarMetrics:属于UIBarButtonItem

使用:

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:@"btn_fanhui_1"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];