1

I am following the Big Nerd Ranch iOS Programming Guide(3rd Edition), and have followed everything it says for creating this project. I am getting an error I do not know how to fix though, as I'm new to iOS. I was initially having a problem with my program giving me this error when I used Single-View Based Application from the template in Xcode:

2012-05-25 16:02:12.926 Whereami[1083:707] Application windows are expected to have a root view controller at the end of application launch

After scanning some forums I found out I need to set my MainInterface in Xcode:

Before - https://i.stack.imgur.com/BrKR1.png

After - https://i.stack.imgur.com/8BfgT.png

After fixing the error above by adding the xib filename to the MainInterface text box in the settings I am getting this error:

    2012-05-25 16:04:09.068 Whereami[1102:707] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x11f620> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key activityIndicator.
*** First throw call stack:
(0x3507b88f 0x364a2259 0x3507b5c5 0x30eb6323 0x30eb5e23 0x30e8ff09 0x34fda7d3 0x34fdb461 0x323111af 0x3231294d 0x32248509 0x320d1893 0x320cb8d7 0x32099c6b 0x3209970f 0x320990e3 0x362ce22b 0x3504f523 0x3504f4c5 0x3504e313 0x34fd14a5 0x34fd136d 0x320caa13 0x320c7e7d 0x7ebd7 0x7eb7c)
terminate called throwing an exception

Here are my source files:

AppDelegate.m - https://i.stack.imgur.com/548u4.png

WhereamiViewController.h WhereamiViewController.m

View - https://i.stack.imgur.com/o5WYs.png

Run- https://i.stack.imgur.com/MLgKd.png

I am stumped, and need to figure this out so I can move on and eventually finish this book. I need to be able to complete my first app for work by next week.

Cœur
  • 37,241
  • 25
  • 195
  • 267
kamran619
  • 531
  • 10
  • 32
  • self.window.rootViewController = yourMainView in applicationdidFinishLaunching method – Kaan Dedeoglu May 25 '12 at 20:54
  • That's what my application is already doing. That code was generated by Xcode – kamran619 May 25 '12 at 21:02
  • One more suggestion, the crash log mentions activityIndicator, are you accessing that in anyway? try temporarily deleting it from the .h file as well as the xib file and see if it still crashes – Kaan Dedeoglu May 25 '12 at 21:08

1 Answers1

1

The question text seems like you are asking this... One way you can set it is like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    LoginViewController* loginView = [[[LoginViewController alloc]initWithNibName:nil bundle:nil]autorelease];
    mainNavController = [[UINavigationController alloc]initWithRootViewController:loginView];

    //here is the magic line
    [_window addSubview:mainNavController.view];

    [self.window makeKeyAndVisible];
    return YES;
}

Or you can do it without the mainNavController:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        // Override point for customization after application launch.
    LoginViewController* loginView = [[[LoginViewController alloc]initWithNibName:nil bundle:nil]autorelease];

    [_window addSubview:loginView.view];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

The title seems like your asking this... Now the NSUnknownKeyException error usually crops up when you try to access a selector or a member of a class that does not exist or is spelled wrong (Usually the latter for me!). You can think of classes like a dictionary and calling a member, or function, is like asking for a dictionary object by it's key. Ex.

`@selector(misspelledFunctionName:)` 

or

[object functionThatIsMisspelledOrNotDefinedInObject];

I am unsure which question is being asked so I tried to answer both. Hopefully that will help :)

EDIT: These both ended up being the answer, or part of it anyways. The UIApplication did not have the correct view assigned to it so xib was sending keys that did not exist and caused it to crash. I removed the root view assignment from the plist (result no crashes but blank screen) then assigned the view like the above (the view displayed perfectly!).

Kibitz503
  • 867
  • 6
  • 10
  • I posted my code above and fixed the question. I am not sending any messages to objects that don't implement them. The functionality of this app is actually very simple and there isn't much going on at all in it. Your suggestion above didn't help e with my specific problem, although I do appreciate you trying. Do you have anymore suggestions? – kamran619 May 25 '12 at 20:49
  • Hey, It looks like activityIndicator is being called from somewhere on a class object that does not contain an activityIndicator. It's saying that UIApplication does not know what activityIndicator is. Try doing a global project search for activityIndicator and make sure it is being called on the class that you think it is. The problem is there somewhere. Note:You can do a global search in the far left window by clicking the magnifying glass. – Kibitz503 May 25 '12 at 21:13
  • The only place it's in is the .h file to declare it, and in my .m in the call to dealloc. It sets it to nil. – kamran619 May 25 '12 at 21:21
  • Did you make sure to delete the [activityIndicator release] statement and the @synthesize activityIndicator statements that were automagically generated for you? If all else fails feel free to zip and email it to me tom@creoagency.com I don't mind taking a quick peek. – Kibitz503 May 25 '12 at 21:22
  • What's your email? I can't locate it when I click on your profile. EDIT:Sent! – kamran619 May 25 '12 at 21:24
  • I'm using ARC btw not manually managing memory. – kamran619 May 25 '12 at 21:28