您可以做的一件事是在方法中添加您的图像,并在viewWillAppear:
方法时将其从导航栏中删除viewWillDisappear:
。相关代码块如下。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UINavigationBar *bar = [self.navigationController navigationBar];
UIImageView *barImg=[[UIImageView alloc]initWithFrame:CGRectMake(2, 3, 49, 39)];
barImg.image=[UIImage imageNamed:@"smalllogo.png"];
barImg.tag = 100;
[bar addSubview:barImg];
[barImg release];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
UINavigationBar *bar = [self.navigationController navigationBar];
[[bar viewWithTag:100] removeFromSuperview];
}
或者这是另一个简单的解决方案。将以下代码段添加到viewWillAppear:
方法中
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"smalllogo.png"]]];
[self.navigationItem setLeftBarButtonItem:item];
[item release];