0

i was just writing my App and suddenly my App Logs Out:

Application windows are expected to have a root view controller at the end of application launch

I thought i could be something i wrote in the last minute so i pressed "cmd + z" to go back! But the log does not disappear. So i looked up for that issue and they said i should add this to my AppDelegate.m:

self.window.rootViewController = self.viewController

I added a property to AppDelegate.h:

@property ViewController *viewController;

That is my AppDelegate.m at this moment:

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc]init];
    self.window.rootViewController = self.viewController;
    return YES;
}

@end

Okay with that solution it worked, but not correct. The background Image stayed also the UIView's but all Labels are gone. What should I do?

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247

1 Answers1

1

You have to load you viewcontroller using instantiateViewControllerWithIdentifier,

Use this in appdelegate

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                         bundle: nil];
self.viewController =(ViewController*)[mainStoryboard
                                                   instantiateViewControllerWithIdentifier: @"ViewController"];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible]; 
return YES;

NOTE: Make sure you give correct identifier name,

Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
  • *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier 'ViewController'' – user3123470 Dec 31 '13 at 12:35
  • @user3123470: As i said please give correct identifier name.you are giving wrong identifier name. – Toseef Khilji Dec 31 '13 at 12:37
  • @user3123470: http://stackoverflow.com/a/8315472/1597744 check this for set your viewcontroller identifier from storyboard. – Toseef Khilji Dec 31 '13 at 12:39
  • Yes I understood. I tried every name, but i does not work. My ViewController ist called "ViewController" – user3123470 Dec 31 '13 at 12:39
  • have you tried http://stackoverflow.com/a/8315472/1597744 this way ? here set you identifier to **ViewController**. – Toseef Khilji Dec 31 '13 at 12:40
  • Yes I did, but I am using a ViewController, there is no section for "Identifier" only Titel. There is a section under it, called Initial Scene, but it is on. – user3123470 Dec 31 '13 at 12:44
  • go to story board, select your viewcontroller and set it, http://i.imgur.com/z3Isf6x.png – Toseef Khilji Dec 31 '13 at 12:50
  • @user3123470: check http://i.imgur.com/z3Isf6x.png image and according to it set. – Toseef Khilji Dec 31 '13 at 12:50
  • Thanks for that Foto, so i entered "ViewController" but same error, i copied the name of ViewController in the Class Section beyond it. There are no typo failures. But it does not work. (Just for a trie I also entered "Main" Storyboard Name, as well, also entered "Main.storyboard" same error) – user3123470 Dec 31 '13 at 12:57
  • Thanks for your help, i don't understand either. It just happened, the app was working fine 3Minutes before that! But you're first solution is working fine: This one: self.viewController = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil]; [self.window makeKeyAndVisible]; – user3123470 Dec 31 '13 at 13:02