9

I have been stuck with this warning for several hours now. I've looked around SO for answers, attempted all the ones I found and couldn't find the solution. Here's the run-down of the code I have, which Xcode generated by default.

This is in my AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

I have this on main.m (according to this answer)

int main(int argc, char *argv[])
{
    @autoreleasepool {
        int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        return retVal;
    }
}

I also have all the connections in my MainWindow.xib connected correctly. So I'm at a loss right now. Anything that I could be missing? Thanks in advance!

Community
  • 1
  • 1
Raphael Caixeta
  • 7,808
  • 9
  • 51
  • 76
  • 1
    The answer that is marked as accepted for your linked question happens to be the one that solved the problem for the author of the question. There are 36 other answers listed there, describing a laundry list of other possibilities. – Sergey Kalinichenko Jul 17 '12 at 04:10
  • @dasblinkenlight That is a strange comment. – rob mayoff Jul 17 '12 at 04:11
  • @robmayoff I tried re-phrasing it to be less strange. The question the OP linked has many answers, each one describing a different problem leading to that same warning, and ways to fix it. The OP mentions fixing the problem as described in the accepted answer, but it does not sound like he has tried other 36 recommendations. – Sergey Kalinichenko Jul 17 '12 at 04:15
  • Did you init your navigation controller? Is it in your MainWindow.xib? – Selkie Jul 17 '12 at 04:15
  • 1
    @dasblinkenlight Nevermind. I misunderstood your comment. – rob mayoff Jul 17 '12 at 04:22
  • 1
    The given link might help http://stackoverflow.com/questions/7520971/applications-are-expected-to-have-a-root-view-controller-at-the-end-of-applicati – Ambili B Menon Oct 12 '12 at 09:37
  • Other dupes: http://stackoverflow.com/q/12784411/9530 http://stackoverflow.com/q/8706828/9530 http://stackoverflow.com/q/8190567/9530 http://stackoverflow.com/q/9844626/9530 and maybe more – Adam Rosenfield Mar 08 '13 at 20:42

4 Answers4

19

It's odd to be setting your window's rootViewController in application:didFinishLaunchingWithOptions: if you have a MainWindow.xib. Usually a project follows one of three templates:

  • Some projects have a MainWindow.xib. The target's “Main Interface” is set to “MainWindow” in the target's Summary tab (or in its Info.plist). This xib's File's Owner is UIApplication. The xib contains an instance of AppDelegate, connected to the File's Owner's delegate outlet. The xib also contains a UIWindow, whose rootViewController outlet is connected to a UIViewController (or subclass, such as UINavigationController), which is also in the xib. By the time the application delegate receives the application:didFinishLaunchingWithOptions: message, the xib is entirely loaded, so the window and its root view controller are already set up.

  • Other projects don't have a MainWindow.xib. The target's “Main Interface” is empty. Instead, the UIApplicationMain function creates an instance of AppDelegate, sets it as the UIApplication's delegate, and sends it the application:didFinishLaunchingWithOptions: message. The app delegate handles that message by creating a UIWindow, creating a view controller (or several), and setting the window's rootViewController property. The default version looks like this:

    - (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;
    }
    
  • Some projects have a MainStoryboard.storyboard. I'm not going to describe this in detail because it doesn't seem relevant to your problem.

The problem you're describing makes it sound like you're using half of the first template, and half of the second template. That won't work. You need to decide which approach you're taking, and go all-in.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
2

You can open xib file and right-click "File's Owner" in Placeholders. If view didn't connect to View outlet then hold "Ctrl" key and drag right mouse click to design, then run again ^^ (do not drag to particular control, drag to background design when appear border View).

Lam Vinh
  • 21
  • 1
1

I have this message because I had in my RootViewController @property(weak, nonatomic) IBOutlet UIView* loadView; and viewDidLoad was called twice... Rename it to something else...

sag
  • 177
  • 1
  • 6
0

I have solve issue in my project, Follow the below steps to solve it..

1) Open the main view controller nib file, that file you have reference in appDelegate eg.ViewCotroller.xib

2) On nib file check the view connection, if not connected to file owner then connect it.

3) Now run the project.

Girish
  • 4,692
  • 4
  • 35
  • 55
user2168844
  • 73
  • 1
  • 1
  • 9