如何仅为一个视图设置 UINavigationController 图像,然后为其余视图设置另一图像?
我正在尝试为我的导航控制器设置背景图像。在第一个视图中,我想显示不同的图像,然后在每个其他视图中显示相同的图像。 目前我得到的是我能够在第一个视图上显示图像,但不知何故我无法删除它及其与下一个视图上的其他图像的重叠。 这是代码:
- (void)viewDidLoad {
[super viewDidLoad];
navImage = [[UIImageView alloc]init];
navImage.image = [UIImage imageNamed:@"iphone_dashboardFirst.png"];
WBWAppDelegate * appDelegate = [(WBWAppDelegate*)[UIApplication sharedApplication]delegate];
appDelegate.rootNav.navigationItem.titleView = navImage;
}
-(void)viewWillDisappear:(BOOL)animated
{
navImage.image = [UIImage imageNamed:@"iphone_dashboard_header.png"];
WBWAppDelegate * appDelegate = [(WBWAppDelegate*)[UIApplication sharedApplication]delegate];
appDelegate.rootNav.navigationItem.titleView = navImage;
}
I am trying to set the background image for my navigation controller. On the very first view i want to display a different image and then same in every other view.
Currently what i got is i am able to display the image on first view but somehow i am not able to remove it and its overlapping with other image on the next view.
Here's the code:
- (void)viewDidLoad {
[super viewDidLoad];
navImage = [[UIImageView alloc]init];
navImage.image = [UIImage imageNamed:@"iphone_dashboardFirst.png"];
WBWAppDelegate * appDelegate = [(WBWAppDelegate*)[UIApplication sharedApplication]delegate];
appDelegate.rootNav.navigationItem.titleView = navImage;
}
-(void)viewWillDisappear:(BOOL)animated
{
navImage.image = [UIImage imageNamed:@"iphone_dashboard_header.png"];
WBWAppDelegate * appDelegate = [(WBWAppDelegate*)[UIApplication sharedApplication]delegate];
appDelegate.rootNav.navigationItem.titleView = navImage;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是在下一个控制器的 viewDidLoad: 中执行与这里相同的操作。 viewWillDisappear: 之前也给我带来了一些麻烦,我不太清楚为什么。
编辑
您可以检查以下任何方法是否有效:
这些是我能想到的唯一可能有效的方法。
The easyest way to do this is to do the same thing you did here in the viewDidLoad: in the viewDidLoad: of the next controller. The viewWillDisappear: has caused me some trouble before aswell, I'm not really sure why.
EDIT
You could check if any of the following methods work:
These are the only methods I could think of that might work.