IOS pushVIewController失败

第一种情况:self.navigationController为空

需要在AppDelegate.m文件里把window 的rootController设置为navigationController ,然后navigationController的子控件设置为你要使用跳转功能的view

如下AppDelegate.m文件

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window=[[UIWindow alloc]init];
    UINavigationController *naviVC=[[UINavigationController alloc]initWithRootViewController:[[LoginViewController alloc]init]];
    self.window.rootViewController=naviVC;
    return YES;
}

第二种情况:xib连线问题

如果你要设置的xib是viewController类型的,要在xib的左上角fileOwner上设置其Class类型为viewController的全名,然后把fileOwner下面的View与fileOwner连线。使用的时候是[[XXXViewController alloc]initWithNibName:NSStringFromClass([XXXViewController class]) bundle:nil] 跟View不同

如果xib是view的时候使用下面这语句 方法返回是一个数组 所以要选择lastObject

[[NSBundle mainBundle]loadNibNamed:@"XXXxib" owner:nil options:nil].lastObject

猜你喜欢

转载自blog.csdn.net/MChuajian/article/details/84818605
今日推荐