1
votes

Okay so I'm trying to add a subview to my navigationController's navigation bar, which works perfectly, however, when pushing a detail controller, I don't want that subview from the pushing controller to be seen in the detail view controller's navigation bar.

I appreciate any help/pointers offered. To restate: I need the subview to only be displayed in the root of the navigation controller, and to not be in any detail controllers.

Here's my current code for creating and adding the navigationController's subview:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.ImageView = [[UIImageView alloc]init];
    self.ImageView.frame = CGRectMake(0, 8.5, 320, 36);
    self.ImageView.contentMode = UIViewContentModeScaleAspectFit;
    self.ImageView.image = [UIImage imageNamed:@"Logo"];
    self.ImageView.clipsToBounds = YES;
    [self.navigationController.navigationBar addSubview:self.ImageView];
}
4
why you add uiimageview on navigation bar. you can simply try setBackgroundImage - codercat
you don't know setBackgroundImage of UINavigationBar - codercat
No, that's not what I'm after at all. I'm animating a logo in. - klcjr89
animating means your are implement in code or use GIF image for that - codercat
could possibly post your screen shot - codercat

4 Answers

2
votes

The best approach is to

  1. Add a tag to your imageView.
  2. Access your imageView using tag & set it's alpha to 1 in viewWillAppear of your mainViewcobtroller where you want to show this.
  3. In new viewcontroller's viewWillAppear method, access the view with same tag & then set it's alpha to 0.

That's should solve your problem Should you need code, plz comment.

1
votes

Perhaps you could tag the view, self.ImageView.tag = 100; Then in the detail controller's viewWillAppear:

 UIView view = (UIView *) [self.navigationControler.navigationBar viewWithTag:100];
 view.hidden = true;

and in viewWillDisappear

 UIView view = (UIView *) [self.navigationControler.navigationBar viewWithTag:100];
 view.hidden = false;
1
votes

add this line when you push to otherViewControllers

 [[self.navigationController.navigationBar viewWithTag:101] removeFromSuperview];

recreate back from other viewController;

- (void)viewWillApper
{

    self.ImageView = [[UIImageView alloc]init];
    self.ImageView.frame = CGRectMake(0, 8.5, 320, 36);
    self.ImageView.contentMode = UIViewContentModeScaleAspectFit;
    self.ImageView.image = [UIImage imageNamed:@"Logo"];
    self.ImageView.clipsToBounds = YES;
    self.ImageView.tag =101;
    [self.navigationController.navigationBar addSubview:self.ImageView];
}
0
votes

This will only affect the invoking view ocontroller:
In the Root viewcontroller of your navigationController

- (void) viewDidLoad {
        // Create / instantiate from Nib / Use already initialized UIView
        [self.navigationItem setTitleView:<your subView here>];
}

When you navigate to some other viewController, the subview won't be there.