我已经尝试了我在谷歌和stackoverflow上阅读的所有内容,但似乎没有任何建议可行。我已经坚持了2天试图解决它但我希望你们可以帮助我并建议我没有尝试过的东西......
这是我尝试过的,似乎没有用:
这些似乎没有工作我仍然得到下面的错误,它不会加载我的应用程序在模拟器上它只是停在黑色加载屏幕
**2013-08-27 12:07:15.057 Project52[647:11303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/Deondrae/Library/Application Support/iPhone Simulator/6.1/Applications/A350F56C-CC1C-462A-8D7C-63F2CB037EBC/Project52.app> (loaded)' with name 'ViewController1''
*** First throw call stack:
(0x159b012 0x12a8e7e 0x159adeb 0x408ef9 0x2cd7e7 0x2cddc8 0x2cdff8 0x2ce232 0x21d3d5 0x21d76f 0x21d905 0x226917 0x2bb5 0x1ea157 0x1ea747 0x1eb94b 0x1fccb5 0x1fdbeb 0x1ef698 0x25fddf9 0x25fdad0 0x1510bf5 0x1510962 0x1541bb6 0x1540f44 0x1540e1b 0x1eb17a 0x1ecffc 0x56ad 0x28d5)
libc++abi.dylib: terminate called throwing an exception
(lldb)**
我怀疑这个错误是由于下面的代码引起的...代码看起来加载了一个xib但这是xcode 4.6所以我们正在使用故事板...我可以改变代码来尝试制作它工作/加载故事板而不是过时的xib?
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController1 alloc] initWithNibName:@"ViewController1" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
更新:这就是我现在在appdelegate.m中的内容(在尝试建议之后),但我仍然收到错误:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[UIStoryboard storyboardWithName:@"ViewController1" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController1"];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
更新2:我仍然收到错误('NSInvalidArgumentException',原因:'无法找到名为'ViewController1'的故事板)
这就是我在appdelegate.h中所拥有的。
#import <UIKit/UIKit.h>
@class ViewController1;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic) UIViewController *viewController;
@property (nonatomic) UINavigationController *navigationController;
@property (nonatomic) UIStoryboard* storyboard;
@property (strong, nonatomic) UIWindow *window;
@end
这就是我在appdelegate.m中所拥有的
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.storyboard = [UIStoryboard storyboardWithName:@"storyboard" bundle:nil];
self.viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:self.viewController];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
}
更新3:
在appdelegate.h和.m文件中的注释中使用@calin chitu代码似乎已经摆脱了错误...但是现在我特意警告我在他提供的代码上关闭括号。 m文件中写着“警告:控制到达无效功能的结束”只有跳过它的方法是启用断点但警告仍然显示...我该如何摆脱这个?
更新4:
添加返回YES;在@calin Chitu在评论中提供的代码的末尾,它应该摆脱警告。他的回答是正确的,并且工作得很好,但我没有足够的要点来标记答案,因为任何人都会越过这个错误使用他的代码/建议它的工作 - 不要忘记返回是的;
答案 0 :(得分:1)
如果您想从appdelegate启动故事板:
at appdelegate.h
@property (nonatomic) UIViewController *viewController;
@property (nonatomic) UINavigationController *navigationController;
@property (nonatomic) UIStoryboard* storyboard;
@property (strong, nonatomic) UIWindow *window;
at appdelegate.m
self.storyboard = [UIStoryboard storyboardWithName:@"yourstoryboardname" bundle:nil];
self.viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:self.viewController];
[self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
确保在storyboard中为Storycontroller设置了StoryboardId作为ViewController1。
您还可以跳过上面的整个代码,方法是转到项目设置,摘要,并使用您创建的故事板设置主故事板。
答案 1 :(得分:1)
您可能会在使用故事板和使用单个nib文件之间感到困惑。你有一个ViewController1.xib吗? 当你告诉我将故事板包含到边界时,我认为ViewController1是你(或你的一个)故事板的一部分。如果是这样,那就去:
[self.storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
当您在app delegate中而不在视图控制器中时使用:
self.viewController = [[UIStoryboard storyboardWithName:@"yourstoryboardname" bundle:nil] instantiateViewControllerWithIdentifier:@"ViewController1"];