Reputation:
ANOTHER PROBLEM:
Even with this code: I still get the error of
"Application windows are expected to have a root view controller at the end of application launch"
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SliderGaloreViewController *sliderGaloreViewController = [[SliderGaloreViewController alloc] init];
self.window.rootViewController = sliderGaloreViewController;
[self.window makeKeyAndVisible];
return YES;
I decided to use a storyboard rather than many XIB files now, and I have two pieces of code giving me SIGABRT errors. Could you have a look at them and indicate how to fix the errors. Thanks in advance!
UPDATE 1:
By the way, the error is:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "SliderGaloreViewController" nib but the view outlet was not set.'
Cause 1 (in 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;
}
Cause 2 (in 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];
}
Upvotes: 0
Views: 132
Reputation: 45490
initWithNibName
is not used in storyboard anymore, forget completely about nibs.
SliderGaloreFlipsideView
is the indentifier meaning the storyboardId
you give when designing in XCode/
- (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;
}
If you were trying to set the root controller, then you remove all the code and just set it in the storyboard:
Upvotes: 1