2015-05-29 61 views
0

我有一些困難,以設置圖像..有什麼奇怪的,因爲在不同的控制器,它的工作。可能self.navigationItem是無效的,但爲什麼如果我只是推ViewController從不同ViewController ..?設置後退按鈕自定義Outlook不起作用

我已經試過:

// preview buttonImage shows that image is correct and exists 
UIImage *buttonImage = [[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithTitle:@"TEST" style:UIBarButtonItemStylePlain target:nil action:NULL]; 
[buttonItem setBackButtonBackgroundImage:buttonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
self.navigationItem.backBarButtonItem = buttonItem; 

不同的方法:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
[button setTitle:@"TEST" forState:UIControlStateNormal]; 
[button setImage:buttonImage forState:UIControlStateNormal]; 
buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; 
self.navigationItem.backBarButtonItem = buttonItem; 

我想,也許self.navigationItem是錯誤的,但它似乎存在:

NSLog(@"%@, %@", self.navigationItem, self.navigationItem.backBarButtonItem); 
--CONSOLE-- MyApp[56574:3827402] <UINavigationItem: 0x7b6ecd10>, <UIBarButtonItem: 0x7b6f01c0> 

我甚至試圖設置:

self.navigationItem.backBarButtonItem = nil; 

什麼也似乎沒有工作。

- 編輯 -

但是下面的代碼做的工作:

[self.navigationItem setHidesBackButton:YES]; 

什麼建議,那self.navigationItem是有效的。

回答

0

很明顯。我忘了,對於新的iOS我設置:

UIImage *backImage = [UIImage imageNamed:@"back"]; 
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backImage forState:UIControlStateNormal barMetrics:UIBarMetricsCompact]; 

所以我需要去改變它爲控制器,在這裏我想用不同的圖像。