A Douglas Stack
A Douglas Stack

Reputation: 1

Why doesn't my app have any code under the (BOOL)application:(UIApplication *) in the appDelegate?

As far as I know when I open the AppDelegate.m file it should have code that resembles this in it.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:  
(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" 
bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

return yes;

But when I open mine it only has the comment in there and the

return yes;

Also, when I input all that code manually it tells me for the self.viewController line that the property 'viewController' not found on object of type 'AppDelegate *' and also against 2 lines below it for the next instance of self.viewController.

Why does this happen and how can I fix it?

Upvotes: 0

Views: 56

Answers (2)

Amit Kalghatgi
Amit Kalghatgi

Reputation: 367

If you select Project Template other then "Empty Application", Xcode will create project as default Storyboard Application.

Check if you have Main.storyboard in your app. if You want to add UIViewController manually try creating Application with Project Template "Empty Application" and then add New Objective C File (UIViewController with xib) to project and add the following code.

self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;

Upvotes: 0

rob mayoff
rob mayoff

Reputation: 385988

If you created your project with a storyboard (which has been the only option for a while now), you don't need that code. UIApplicationMain creates your UIWindow, assigns it to your application delegate's window property, and loads the window's root view controller from the storyboard.

Upvotes: 2

Related Questions