另一个问题:
即使使用此代码:我仍然会收到错误
"应用程序窗口应在应用程序启动结束时具有根视图控制器"
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SliderGaloreViewController *sliderGaloreViewController = [[SliderGaloreViewController alloc] init];
self.window.rootViewController = sliderGaloreViewController;
[self.window makeKeyAndVisible];
return YES;
我现在决定使用故事板而不是许多XIB文件,我有两段代码给我SIGABRT错误。你能看看它们并说明如何解决这些错误。提前谢谢!
更新1:
顺便说一句,错误是:
由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:' - [UIViewController _loadViewFromNibNamed:bundle:]加载了" SliderGaloreViewController"笔尖但未设置视图插座。'
原因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;
}
原因2(在Viewcontroller.m中):
- (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];
}
答案 0 :(得分:1)
initWithNibName
不再用于故事板,完全忘记了笔尖。
SliderGaloreFlipsideView
是在XCode /
storyboardId
的标识符
- (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;
}
如果您尝试设置根控制器,则删除所有代码并将其设置在故事板中: