我正在编写一个 iOS 应用程序;没有 ARC,也没有 Storyboard。
我在导航 Controller 中有一个 View Controller 。它应该有推到第二个 View 的表格 View 和导航按钮。
这是我得到的错误:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "ViewController" nib but the view outlet was not set.'
*** First throw call stack:
(0x1c8d012 0x10cae7e 0x1c8cdeb 0xf2f18 0xf3418 0xf3648 0xf3882 0x42a25 0x42dbf 0x42f55 0x4bf67 0x2a88 0xf7b7 0xfda7 0x10fab 0x22315 0x2324b 0x14cf8 0x1be8df9 0x1be8ad0 0x1c02bf5 0x1c02962 0x1c33bb6 0x1c32f44 0x1c32e1b 0x107da 0x1265c 0x2442 0x2375)
libc++abi.dylib: terminate called throwing an exception
(lldb)
AppDelegate 中的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewCon = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
self.navCon = [[UINavigationController alloc]initWithRootViewController:self.viewCon];
self.navCon.navigationBar.tintColor= [UIColor greenColor];
self.viewCon.title= @"First View";
self.tblView = [[UITableView alloc] init];
NSMutableArray *viewArr=[[NSMutableArray alloc] init];
[viewArr addObject:self.navCon];
self.navBar = [[UINavigationBar alloc] init];
self.viewCon.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Second View" style:UIBarButtonSystemItemAdd target:self action:(nil)];
[self.window addSubview:self.navBar];
self.window.rootViewController = self.viewCon;
[self.window makeKeyAndVisible];
return YES;
}
在这个阶段,我什至无法运行应用程序。可能是什么问题?
最好的祝福
最佳答案
loaded the "ViewController" nib but the view outlet was not set.
您似乎忘记连接
view
View Controller 的导出到 ViewController.xib 文件中的实际 View 。您的 xib 文件有一个文件的所有者。您可能已将其设置为
ViewController
(我想它是 UIViewController
的子类)。现在,如果您转到右侧 Pane 并显示绑定(bind) Pane (最后一个,带有一个小箭头),您将看到 View Controller 有一个名为
view
的导出。 :从右侧的小圆圈拖动到您在 xib 中创建的 View 。
关于ios - 运行 Non-Storyboard 应用程序的运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14549924/