0

我在视图控制器之间切换时遇到问题。

我的 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”

可能是什么问题?

4

2 回答 2

1

可能只是一个拼写错误的 NIB 名称:

initWithNibName:@"pipeViewDiease"

应该:

initWithNibName:@"pipeViewDisease"
                            ^
于 2013-02-28T13:22:41.947 回答
1

除非是拼写错误(应该是 pipeViewDisease),否则这个错误通常发生在在 xCode 环境之外重新命名文件时。

要解决这个问题:

  • 从项目中删除有问题的文件
  • 将文件重新导入您的项目。
于 2013-02-28T13:23:03.323 回答