开发者

iOS 5 UINavigationBar removing subviews ( image subview) removes navigation bar

开发者 https://www.devze.com 2023-04-12 10:50 出处:网络
In my application that works fine on iOS 4 navigationBar dissappeared starting iOS 5. Here is what I figured caused issue: I was removing subviews in RootViewController viewWillAppear method:

In my application that works fine on iOS 4 navigationBar dissappeared starting iOS 5. Here is what I figured caused issue: I was removing subviews in RootViewController viewWillAppear method:

for(UIView* view in self.navigationController.navigationBar.subviews)
    {
        if ([view isKindOfClass:[UILabel class]]) 
        {
            [view removeFromSuperview];
        }
        if([view isKindOfClass:[UIImageView class]])
        {
            [view removeFromSuperview];
        }
    }

I was doing this because Second view controlle开发者_运维问答r that I push onto navigation controller add's image and label to navigation bar which I have to remove when view is popped. In iOS 5 the above code removes navigationBar. How to fix this or right way of doing it to support both iOS4 and iOS 5 ?


setTag for those image and uilabel then removing it from code above did the trick.

for(UIView* view in self.navigationController.navigationBar.subviews)
{
   if(view.tag == 9 || view.tag == 99)
   {
      [view removeFromSuperview];
   }
}


You could make your added views subclasses of their respective UIKit classes and check against those specific subclasses. Really though, to have the clearest, most readable code, you should subclass the navigation controller and navigation bar to allow for a custom image and label to be drawn such that you could simply set the background image and foreground label to nil. It would take a little time to put together, but the end result would be much more extendable.

0

精彩评论

暂无评论...
验证码 换一张
取 消