Question

I have one label which I am showing on UINavigationBar using addSubView Property and I am getting like:enter image description here

But when I am going to secondView Controller, it is looking like:enter image description here

It appears on Back Button of Second Controller. So how to remove "Status" Label from second UI.

Thank You.

Was it helpful?

Solution 2

In first View controller -

-(void)viewWillAppear:(BOOL)animated 
{
    //Add Label on UINavigationBar
      [super viewWillAppear:animated];
      [self.navigationController.navigationBar addSubview:navLabel];
}

-(void)viewWillDisappear:(BOOL)animated 
{
    // Remove label from UINavigationBar
    [super viewWillDisappear:animated];
    [navLabel removeFromSuperview];
}

OTHER TIPS

Don't add subviews to the navigation bar. It's not made for that. I recommend you to read the iOS human interface guidelines and to use a UIBarButtonItem to properly add controls to the navigation bar.

You should tag your subview and search for it among subviews of navigation bar in your second view controller and then [subview removeFromSuperview].

You shouldn't add subviews to your navigation bar, you can use navigation items to achieve that kind of stuff. You can init a UIBarButtonItem with initWithCustomView: which has that label in it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top