Objective c 不再使用故事板而不是XIB文件

Objective c 不再使用故事板而不是XIB文件,objective-c,xcode,storyboard,xib,Objective C,Xcode,Storyboard,Xib,另一个问题: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; if ([prefs objectForKey:@"PuzzlePicture"] == nil) { [prefs

另一个问题:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:     (NSDictionary *)launchOptions
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

if ([prefs objectForKey:@"PuzzlePicture"] == nil) {
    [prefs setBool:FALSE forKey:@"Refresh"];
    [prefs setInteger:0 forKey:@"PuzzlePicture"];
    [prefs setBool:TRUE forKey:@"CountMoves"];
    //[prefs setBool:TRUE forKey:@"Timer"];
    [prefs setInteger:1 forKey:@"PuzzleLayoutX"];
    [prefs setInteger:1 forKey:@"PuzzleLayoutY"];
}

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SliderGaloreViewController *sliderGaloreViewController = [[SliderGaloreViewController   alloc] initWithNibName:@"SliderGaloreViewController" bundle:nil];
self.window.rootViewController = sliderGaloreViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (IBAction)showInfo:(id)sender
{
SliderGaloreFlipsideViewController *controller = [[SliderGaloreFlipsideViewController alloc] initWithNibName:@"SliderGaloreFlipsideViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
}
即使有这样的代码:我仍然得到

“应用程序启动结束时,应用程序窗口应具有根视图控制器”

我决定现在使用一个故事板而不是许多XIB文件,我有两段代码给出了SIGABRT错误。您能看一下它们并指出如何修复错误吗。提前谢谢

更新1: 顺便说一下,错误是:
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UIViewController\u loadViewFromNibNamed:bundle:]加载了“SliderGaloreViewController”nib,但未设置视图出口。”

原因1(在appdelegate中):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:     (NSDictionary *)launchOptions
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

if ([prefs objectForKey:@"PuzzlePicture"] == nil) {
    [prefs setBool:FALSE forKey:@"Refresh"];
    [prefs setInteger:0 forKey:@"PuzzlePicture"];
    [prefs setBool:TRUE forKey:@"CountMoves"];
    //[prefs setBool:TRUE forKey:@"Timer"];
    [prefs setInteger:1 forKey:@"PuzzleLayoutX"];
    [prefs setInteger:1 forKey:@"PuzzleLayoutY"];
}

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SliderGaloreViewController *sliderGaloreViewController = [[SliderGaloreViewController   alloc] initWithNibName:@"SliderGaloreViewController" bundle:nil];
self.window.rootViewController = sliderGaloreViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (IBAction)showInfo:(id)sender
{
SliderGaloreFlipsideViewController *controller = [[SliderGaloreFlipsideViewController alloc] initWithNibName:@"SliderGaloreFlipsideViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
}
原因2(在Viewcontroller.m中):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:     (NSDictionary *)launchOptions
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

if ([prefs objectForKey:@"PuzzlePicture"] == nil) {
    [prefs setBool:FALSE forKey:@"Refresh"];
    [prefs setInteger:0 forKey:@"PuzzlePicture"];
    [prefs setBool:TRUE forKey:@"CountMoves"];
    //[prefs setBool:TRUE forKey:@"Timer"];
    [prefs setInteger:1 forKey:@"PuzzleLayoutX"];
    [prefs setInteger:1 forKey:@"PuzzleLayoutY"];
}

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SliderGaloreViewController *sliderGaloreViewController = [[SliderGaloreViewController   alloc] initWithNibName:@"SliderGaloreViewController" bundle:nil];
self.window.rootViewController = sliderGaloreViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (IBAction)showInfo:(id)sender
{
SliderGaloreFlipsideViewController *controller = [[SliderGaloreFlipsideViewController alloc] initWithNibName:@"SliderGaloreFlipsideViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
}

initWithNibName
不再在故事板中使用,完全忘记NIB

SliderGaloreFlipsideView
是标识符,表示在XCode中设计时提供的
故事板ID
/

- (BOOL)application:(UIApplication *)application
               didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

if ([prefs objectForKey:@"PuzzlePicture"] == nil) {
    [prefs setBool:FALSE forKey:@"Refresh"];
    [prefs setInteger:0 forKey:@"PuzzlePicture"];
    [prefs setBool:TRUE forKey:@"CountMoves"];
    //[prefs setBool:TRUE forKey:@"Timer"];
    [prefs setInteger:1 forKey:@"PuzzleLayoutX"];
    [prefs setInteger:1 forKey:@"PuzzleLayoutY"];
}

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

SliderGaloreFlipsideViewController *sliderGaloreViewController = 
(SliderGaloreFlipsideViewController *)[storyboard 
      instantiateViewControllerWithIdentifier:@"SliderGaloreFlipsideView"];

[self.window.rootViewController presentViewController:sliderGaloreViewController 
                                             animated:NO 
                                           completion:nil];

return YES;
}

如果您试图设置根控制器,则删除所有代码并在情节提要中设置:


等等,不,我想我明白了。然而,App delegate中是什么?@gjys2000查看我的编辑,我不知道您该代码在appdelagate中,
Main
是故事板的名称抱歉,我没有指出它是错误的。然而,错误的第二个原因确实不在故事板中——第一个是。我想知道如何解决问题的第一个原因error@gjys2000查看我的ediyBut现在我有一个错误:警告:尝试显示不在窗口层次结构中的视图!2014-09-14 17:07:12.361 SliderGalore益智游戏[4680:70b]预计在应用程序启动结束时,应用程序窗口将有一个根视图控制器