代码之家  ›  专栏  ›  技术社区  ›  Tirth

UINavigationBar不显示?

  •  0
  • Tirth  · 技术社区  · 16 年前

    我正在开发一个应用程序 UINavigationController 在rooViewController中 xib UIView ,代码编写如下。

    @implementation RootViewController
    @synthesize introductionView, WheelView;
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        [self.navigationController setNavigationBarHidden:YES];
    }
    
    #pragma mark 
    #pragma mark strart up screen:
    
    -(void)startIntroductionScreen{
        if(window == nil) {
            window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
        }
        [window addSubview: introductionView];
        [window makeKeyAndVisible]; 
    }
    
    -(void)WheelScreen{
        [window addSubview:carnivalWheelView];
        [window makeKeyAndVisible]; 
        self.navigationController.navigationBar.hidden = NO;    
        [self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"Setting" style:UIBarButtonItemStylePlain target:nil action:nil] animated:YES];
    }
    
    #pragma mark 
    #pragma mark IBAction:
    
    -(IBAction)breakGlass:(id)sender{
        [self startIntroductionScreen];
    }
    
    -(IBAction)anotherView:(id)sender{
        [self WheelScreen];
    }
    

    在上面的代码中,当 -(void)WheelScreen IBAction 调用的另一个视图 UINaviagtionBar 未显示。

    提前谢谢你。

    1 回复  |  直到 7 年前
        1
  •  0
  •   RickiG    16 年前

    您好,您正在添加您的视图直接到窗口,它可能有高度480像素? 这意味着您正在用carnivalWheelView覆盖navigationController。

    carnivalWheel应该是UIViewController的子类,然后应该将其添加到navigationController而不是窗口。

    CarnivalWheel *cw = [[CarnivalWheel alloc] init];
    [self.navigationController pushViewController:cw animated:YES];
    [cw release];
    

    现在,CarnivalWheel是navigationController的“子对象”,不会用视图覆盖它。