Iphone 关闭导航栏图像

Iphone 关闭导航栏图像,iphone,ios,xcode,uiimageview,uinavigationbar,Iphone,Ios,Xcode,Uiimageview,Uinavigationbar,我想关闭导航栏图像而不是背景图像。也就是说,我已在左侧设置了导航栏图像。当我转到下一个控制器时,图像与后退按钮重叠。这是我的主屏幕,图像用蓝色标记 这是我的第二个屏幕,图像重叠 这是我用来在吧台上设置图像的代码 UINavigationBar *bar = [self.navigationController navigationBar]; UIImageView *barImg=[[UIImageView alloc]initWithFrame:CGRectMake(2, 3, 49, 39)

我想关闭导航栏图像而不是背景图像。也就是说,我已在左侧设置了导航栏图像。当我转到下一个控制器时,图像与后退按钮重叠。这是我的主屏幕,图像用蓝色标记

这是我的第二个屏幕,图像重叠

这是我用来在吧台上设置图像的代码

UINavigationBar *bar = [self.navigationController navigationBar];
UIImageView *barImg=[[UIImageView alloc]initWithFrame:CGRectMake(2, 3, 49, 39)];
barImg.image=[UIImage imageNamed:@"smalllogo.png"];

[bar addSubview:barImg];
[barImg release];

现在我不想让图像出现在我的其他屏幕上,我能做些什么呢?

您可以做的一件事是将图像添加到ViewWillDisplay:method的旁边,并在ViewWillEnglish:method消失时将其从导航栏中删除。相关代码块如下所示

    - (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];
}
或者这里有另一个简单的解决方案。将以下代码段添加到视图将显示:方法


您已在导航栏中添加图像,但在移动到其他视图之前未将其删除。 使用`


要将其从superview中删除。

第二屏需要图像消失吗?是。我不希望在我的第二个屏幕中出现这种情况,我已经用另一个解决方案更新了答案。如果你认为这是正确的答案。请接受
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"smalllogo.png"]]];
[self.navigationItem setLeftBarButtonItem:item];
[item release];
-(void)viewWillDisappear:(BOOL)animated{

    [barImg removeFromSuperview];
}`