iOS 5 UINavigationBar 删除子视图(图像子视图)删除导航栏

时间:2023-03-23
本文介绍了iOS 5 UINavigationBar 删除子视图(图像子视图)删除导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在我在 iOS 4 上运行良好的应用程序中,从 iOS 5 开始导航栏消失了.这是我认为导致问题的原因:我正在删除 RootViewController viewWillAppear 方法中的子视图:

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];
        }
    }

我这样做是因为我推送到导航控制器上的第二个视图控制器将图像和标签添加到导航栏,当视图弹出时我必须删除它们.在 iOS 5 中,上面的代码删除了导航栏.如何解决此问题或以正确的方式支持 iOS4 和 iOS 5?

I was doing this because Second view controller 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 ?

推荐答案

为这些图像和 uilabel 设置标签,然后从上面的代码中删除它就可以了.

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];
   }
}

这篇关于iOS 5 UINavigationBar 删除子视图(图像子视图)删除导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:当 hidesBottomBarWhenPushed 为“TRUE"时如何隐藏自定义标签栏按钮 下一篇:以编程方式读取 iPhone 设置(精确设置 -> 常规 -> 日期和时间 -> 自动设置)

相关文章