ios pushViewController 页面不跳转问题解决

挺长时间没写iOS代码了,今天在写页面跳转的时候发现跳转不了,代码是这样的:

-(void)pushClick:(UIButton*)sender{   
    SecondViewController *secondVC = [[SecondViewController alloc]init];  
    secondVC.labelString = _textLabel.text;  
    [self.navigationController pushViewController:secondVC animated:YES];  
}  

这是因为我们默认采用的mainstory启动,当换了viewcontroller启动时,navigationController为空。

所以需要在AppDelegate.m启动中添加:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    FirstViewController *fc = [[FirstViewController alloc]init];  
    UINavigationController *navCtrlr = [[UINavigationController alloc]initWithRootViewController:fc];  
    [self.window setRootViewController:navCtrlr];  
    //navCtrlr.navigationBarHidden = YES;  
    return YES;  
} 
这样页面就能跳转了,但是问题是页面都是黑的啊,解决方案是

self.view.backgroundColor = [UIColor whiteColor];
这样就OK了。。

你可能感兴趣的:(iOS)