Application windows are expected to have

#1

I’ve finished the book up to page 99. I’m at the bottom where it says to build and run the application. The build is successful, but I believe it’s crashing, and I get the error message “Application windows are expected to have a root view controller at the end of application launch”. The following line in HypnosisView.m is highlighted green.

UIBezierPath *path = [[UIBezierPath alloc] init];

I’ve tried a number of solutions online, but none seem to work or even relate to this project.

#2

I don’t mean to derail your thread, but how did you make it that far with the Hypnosis project? I’m on page 91, have followed the instructions carefully, and can’t get the rectangle to appear. My AppDelegate class came with none of the code in place that the example in the book shows, and even after I typed all of the code that was apparently there in earlier versions of Xcode, no rectangle shows up, just a white screen.

Did you struggle with that part as well? How did you get past it? Maybe if I get caught up to your position I can help you with the part you need help on.

#3

I had the same issue. It seems like the latest version of XCode no longer allows you to programmatically create views without having a root view controller defined. I solved this by skipping ahead to Chapter 6 on View Controllers and setting up a basic ViewController. If you finish the steps up until the “Another UIViewController” header, it should work for you and you can return to Chapter 4 wherever you left off - my code is below.

In AppDelegate.m

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    HypnosisViewController *hvc = [[HypnosisViewController alloc] init];
    self.window.rootViewController = hvc; // need a rootViewController

    CGRect firstFrame = CGRectMake(160, 240, 100, 150);

In HypnosisViewController.m (new file)

  • (void)loadView {
    [b] CGRect frame = [UIScreen mainScreen].bounds;
    HypnosisView *backgroundView = [[HypnosisView alloc] initWithFrame:frame];

    // set the backgroundView as the view of this controller
    self.view = backgroundView;[/b]
    }

#4

@alloftheabove
I didn’t have that problem, so I’m not exactly sure what to tell you other than to double check the actual code. But I assume you’ve already done that. The only other problem I’ve had with this book was the actual new project menu being different. I’ve chosen wrong ones in the past, and had to restart a project using a different type. This might be your problem? If it helps, I’m using Xcode 6.4 (6E35b). If you are using a different one, then maybe try that version.

@upstarter
Thanks for your response. I don’t have time to fix it in the immediate future, but I’ll let you know if it works.

#5

[quote=“upstarter”]I had the same issue. It seems like the latest version of XCode no longer allows you to programmatically create views without having a root view controller defined. I solved this by skipping ahead to Chapter 6 on View Controllers and setting up a basic ViewController. If you finish the steps up until the “Another UIViewController” header, it should work for you and you can return to Chapter 4 wherever you left off - my code is below.

In AppDelegate.m

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    HypnosisViewController *hvc = [[HypnosisViewController alloc] init];
    self.window.rootViewController = hvc; // need a rootViewController

    CGRect firstFrame = CGRectMake(160, 240, 100, 150);

In HypnosisViewController.m (new file)

  • (void)loadView {
    [b] CGRect frame = [UIScreen mainScreen].bounds;
    HypnosisView *backgroundView = [[HypnosisView alloc] initWithFrame:frame];

    // set the backgroundView as the view of this controller
    self.view = backgroundView;[/b]
    }[/quote]

Same here. I’ll try to follow your suggestion. Thanks! :slight_smile:

#6

Using your code did not work for me. Something about backgroundView not being declared. But I’m going to do what you did and skip to chapter 6.

#7

This seems to be an Xcode 7 problem exclusively. No one had complained about it before. But anyway, upstarter’s solution worked for me. I went to chapter 6, created the root view controller, and then it worked.