我有这段代码可以更改我的 UINavigationBar 的后退按钮
// Set the custom back button
UIImage *buttonImage = [UIImage imageNamed:@"backag.png"];
//create the button and assign the image
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"selback.png"] forState:UIControlStateHighlighted];
button.adjustsImageWhenDisabled = NO;
//set the frame of the button to the size of the image (see note below)
button.frame = CGRectMake(0, 0, 30, 30);
[button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
//create a UIBarButtonItem with the button as a custom view
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = customBarItem;
// Cleanup
[customBarItem release];
如果我把它放在 viewDidLoad 方法中它工作正常。但是,当我加载下一个视图时,会显示旧样式按钮。为了解决这个问题,我尝试将此代码放在下一个视图的 viewDidLoad 方法中,但随后看不到任何按钮。
关于可能导致这种情况的任何想法?
谢谢!