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