0

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];
}
gjys2000
  • 13
  • 5

1 Answers1

1

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:

enter image description here

meda
  • 44,540
  • 14
  • 88
  • 122
  • Wait no, I think I got it. However what is it in the App delegate? – gjys2000 Sep 14 '14 at 08:54
  • @gjys2000 see my edit, I didnt know you this code was in appDelaguate, `Main` is the name of the storyboard – meda Sep 14 '14 at 08:56
  • Sorry, it was my mistake for not indicating it. However the second cause of error is indeed not in the storyboard - the first one is. I would like to know how to fix the first cause of error – gjys2000 Sep 14 '14 at 09:00
  • @gjys2000 see my ediy – meda Sep 14 '14 at 09:03
  • But now I have this error: Warning: Attempt to present on whose view is not in the window hierarchy! 2014-09-14 17:07:12.361 SliderGalore Puzzle Game[4680:70b] Application windows are expected to have a root view controller at the end of application launch – gjys2000 Sep 14 '14 at 09:08
  • Now I have this error that says, "Application windows are expected to have a root view controller at the end of application launch". What do I do? – gjys2000 Sep 14 '14 at 09:18
  • @gjys2000 are you trying to make it the root view Controller ? if so this does not require any code go into the storyboard and check is initial view controller in xcode property pane (right side) – meda Sep 14 '14 at 09:21
  • The View Controller I want to be shown has initial view controller checked, however when I run the application no view controller appears. – gjys2000 Sep 14 '14 at 09:25
  • I also don't have any NavigationController in the storyboard, just two view controllers and two segues. – gjys2000 Sep 14 '14 at 09:26
  • @gjys2000 embed the rootViewController into a navigation controller – meda Sep 14 '14 at 09:28
  • Okay, I will do that now, but will any of the code you have above need to be changed? Because it doesnt seem like I need to implement any code for rootviewcontroller anymore. – gjys2000 Sep 14 '14 at 09:35
  • no you dont, that is the beauty of story board, this code will only help you to present view modally. for setting a root controller, no code is required unless some complex logic involved – meda Sep 14 '14 at 09:38
  • So I tried having a Navigationcontroller but once I removed the code there was an error, "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "YgU-b0-wQK-view-Cu4-NM-jCd" nib but the view outlet was not set.'" – gjys2000 Sep 14 '14 at 09:45
  • there should not nib invlolved at all , see http://stackoverflow.com/questions/17321027/loaded-nib-but-the-view-outlet-was-not-set-exception – meda Sep 14 '14 at 10:02