Error when quitting iTahDoodle


#1

Hi.

I’ve followed chapter 27 and compiled the application, which runs fine. But when I force quit the app in the simulator, the simulator hangs and I get the following error message in the console: “Applications are expected to have a root view controller at the end of application launch”.

I’ve typed in the code exactly as it’s shown in the book, except for adding the addTask: method in the BNRAppDelegate header file as well.(By the way, why is this not required?)

And another thing: Why is the helper function declared as a pointer, and why do we need to type in (void) as the argument? When calling docPath(), void is omitted.

I’m on Lion 10.7.2 and Xcode 4.2.


#2

I have the same questions.


#3

Several issues can cause this, judging by stackoverflow.com/questions/7520 … -applicati

If this project used Interface Builder, I’d say you overlooked a connection somewhere. Not sure what to suggest, but I’d definitely review that thread.


#4

The SO thread that macintux mentioned is indeed worth a look.

Just to get some different eyes on it, post your application:didFinishLaunchingWithOptions: method implementation here. Sometimes that’s all I need to find a problem that’s been staring me in the face.

There are other possibilities, but they’re more difficult to track down, so I’d like to try them last.


#5

Hi,

The view is set up programatically as in the book, so IB is not used. Here´s my code:

[code]- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSArray *plist = [NSArray arrayWithContentsOfFile:docPath()];
if (plist) {
tasks = [plist mutableCopy];
} else {
tasks = [[NSMutableArray alloc] init];

}


//Create window and frames:
CGRect windowFrame = [[UIScreen mainScreen] bounds];
UIWindow *theWindow = [[UIWindow alloc] initWithFrame:windowFrame];
[self setWindow:theWindow];
CGRect tableFrame = CGRectMake(0, 80, 320, 380);
CGRect fieldFrame = CGRectMake(20, 40, 200, 31);
CGRect buttonFrame = CGRectMake(228, 40, 72, 31);

//tableView:
taskTable = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain];
[taskTable setSeparatorStyle: UITableViewCellSeparatorStyleNone];

[taskTable setDataSource:self];

//taskField:
taskField = [[UITextField alloc] initWithFrame:fieldFrame];
[taskField setBorderStyle:UITextBorderStyleRoundedRect];
[taskField setPlaceholder:@"Type a task, tap Insert"];

//insertButton:
insertButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[insertButton setFrame:buttonFrame];

//define button action
[insertButton addTarget:self action:@selector(addTask:) forControlEvents:UIControlEventTouchUpInside];

[insertButton setTitle:@"Insert" forState:UIControlStateNormal];

[[self window] addSubview:taskTable];
[[self window] addSubview:taskField];
[[self window] addSubview:insertButton];

[[self window] setBackgroundColor:[UIColor whiteColor]];
[[self window] makeKeyAndVisible];

return YES;

}
[/code]


#6

Hi,

I’m receiving the same error with the app.

2012-02-03 21:24:12.891 iTahDoodle[989:f803] Applications are expected to have a root view controller at the end of application launch

[code]- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Attempt to load an existing to-do dataset from an array stored to disk.
NSArray *plist = [NSArray arrayWithContentsOfFile:docPath()];
if (plist) {
// If there was a dataset available, copy it into our instance variable.
tasks = [plist mutableCopy];
} else {
// Otherwise, just create an empty one to get us started.
tasks = [[NSMutableArray alloc] init];
}

// Is tasks empty?
if ([tasks count] == 0) {
    // Put some strings in it
    [tasks addObject:@"Walk the dogs"];
    [tasks addObject:@"Feed the hogs"];
    [tasks addObject:@"Chop the logs"];
}

// Create and configure the UIWindow instance
// A CGRect is a struct with an origin (x,y) and size (width, height)
CGRect windowFrame = [[UIScreen mainScreen] bounds];
UIWindow *theWindow = [[UIWindow alloc] initWithFrame:windowFrame];
[self setWindow:theWindow];

// Define the frame rectangles of the three UI elements
// CGRectMake() creates a CGRect from (x, y, width, height)
CGRect tableFrame = CGRectMake(0, 80, 320, 380);
CGRect fieldFrame = CGRectMake(20, 40, 200, 30);
CGRect buttonFrame = CGRectMake(228, 40, 72, 31);

// Create and configure the table view
taskTable = [[UITableView alloc] initWithFrame:tableFrame
                                         style:UITableViewStylePlain];
[taskTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];

// Make this object the table view's dataSource
[taskTable setDataSource:self];

// Create and configure the text field where new tasks will be typed
taskField = [[UITextField alloc] initWithFrame:fieldFrame];
[taskField setBorderStyle:UITextBorderStyleRoundedRect];
[taskField setPlaceholder:@"Type a task, tap Insert"];

// Create and configure a rounded rect Insert button
insertButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[insertButton setFrame:buttonFrame];

// Buttons behave using a target/action callback
// Configure the Insert button's action to call this object's -addTask: method
[insertButton addTarget:self
                 action:@selector(addTask:)
       forControlEvents:UIControlEventTouchUpInside];

// Give the button a title
[insertButton setTitle:@"Insert"
              forState:UIControlStateNormal];

// Add our three UI elelents to the window
[[self window] addSubview:taskTable];
[[self window] addSubview:taskField];
[[self window] addSubview:insertButton];

// Finalize the window and put it on the screen
[[self window] setBackgroundColor:[UIColor whiteColor]];
[[self window] makeKeyAndVisible];

return YES;

[/code]


#7

Hi,

and me too, I have the same message. Probably an explanation here would make sense what a root controller is anyway and what function it serves ?

I don’t think that adding my code as well enlights anyone here :slight_smile:

Help is much appreciated…

Rgeards

Klaus