How to remove UINavigationBar label.text from second UIView Controller which is coming in first View controller?

StackOverflow https://stackoverflow.com/questions/21406490

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.

有帮助吗?

解决方案 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];
}

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top