self.navigationController is null

前端 未结 3 757
温柔的废话
温柔的废话 2021-01-04 08:24

in my viewcontroller,I have a button,when press the button,entry the navigationController,my code like:

-(IBAction)ShangHaiButtonPressed:(id)sender{
    mark         


        
3条回答
  •  时光取名叫无心
    2021-01-04 09:17

    This code will yield the solution you're looking for:

    -(IBAction)ShangHaiButtonPressed:(id)sender {
         UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self];
         [self.view removeFromSuperview];
         [appDelegate.window addSubview:nav.view];   // appDelegate is the delegate of your Application
         marketViewController = [[MarketViewController alloc] initWithNibName:@"MarketViewController" bundle:nil];
         [nav pushViewController:marketViewController animated:YES];
         [marketViewController release];    
    }
    

提交回复
热议问题