我在视图控制器之间切换时遇到问题。
我的md360AppDelegate.h标题如下所示
#import <UIKit/UIKit.h>
@class md360ViewController;
@interface md360AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) md360ViewController *viewController;
@property (strong, nonatomic) UINavigationController *navigationController;
@end
我的md360AppDelegate.m实现看起来像这样。
#import "md360AppDelegate.h"
#import "md360ViewController.h"
@implementation md360AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[md360ViewController alloc] initWithNibName:@"md360ViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.window setRootViewController:self.navigationController];
[self.window makeKeyAndVisible];
return YES;
}
@end
我正在创建一个UINavigationController实例并将其存储在此类的navigationController属性中。
当用户点击md360ViewController中的按钮时,我想更改ViewController。
我的md360ViewController.h看起来像这样。
@interface md360ViewController : UIViewController
@property IBOutlet UIButton *homePathwayBtn;
@property IBOutlet UIButton *homeDiseaseBtn;
@property IBOutlet UIButton *homePipelineBtn;
- (IBAction)homeButton:(id)sender;
@end
我的实现看起来像
#import "md360ViewController.h"
#import "md360AppDelegate.h"
#import "pipeViewDisease.h"
#import <QuartzCore/QuartzCore.h>
- (IBAction)homeButton:(id)sender {
UIViewController *pipeViewDisease = [[UIViewController alloc] initWithNibName:@"pipeViewDiease" bundle:nil];
[self.navigationController pushViewController:pipeViewDisease animated:YES];
}
当我点击UIButton时,应用程序崩溃并显示以下消息。
由于未捕获的异常而终止应用 'NSInternalInconsistencyException',原因:'无法加载NIB 捆绑:'NSBundle (加载)'名称'pipeViewDiease''
可能是什么问题?
答案 0 :(得分:1)
可能只是一个拼写错误的NIB名称:
initWithNibName:@"pipeViewDiease"
应该是:
initWithNibName:@"pipeViewDisease"
^
答案 1 :(得分:1)
除非是拼写错误(应该是pipeViewDisease),否则在xCode环境之外重命名文件时通常会发生此错误。
解决此问题: