views:

62

answers:

1

I am writing an application where you need to show login screen modally and the app has a tab bar.

I have added tab bar directly to the UIWindow. To flip it to a new view (login view) I have overridden applicationDidFinishLaunching where I check if user has login credentials, then I do not show the login screen otherwise (assuming first time use or logout case) I modally present the login screen. I have given an option of logout in a settings tab inside the app.

I am using [[UIApplication sharedApplication] delegate] call to get instance of app delegate when user logs in first time. This way I get access to the tabBarController that is part of the Application Delegate (as is most of the times). However, when I try to call my loginViewController from the logout option in settings (somewhere in future life cycle), the same call [[UIApplication sharedApplication] delegate] returns me a delegate on which I am not able to use any of the methods I have defined. It gives me "unrecognized selector sent to instance" error at runtime.

I need to understand what exactly the call [[UIApplication sharedApplication] delegate] returns? Does the delegate object it returns change over the period of application life cycle? OR is it a singleton instance through out the app life cycle?

And secondly to resolve this, should I add the tabBar to a view (contained in main window) instead of adding it directly to the UIWindow (as done by the template for Tab Bar application and seems to be the standard practice). Are there any known problems with this approach OR its okay to do so. Any one has tried this? Please let me know.

Thanks Dev.

+1  A: 

It sounds like your class that gets an instance of your singleton delegate doesn't know what it implements. make sure you are #importing your delegate to the class that uses it as [[UIApplication sharedApplication] delegate]. Also, if you get a warning about UIApplication not conforming or whatever, you can cast it to your AppDelegate type to avoid it.

To answer your question about what this call returns, it is a singleton throughout the lifecycle of the app.

To answer the 2nd question, having it in the UIWindow (and thus in the appdelegate) is fine, and probably encouraged, since it is the root controller of your app (from the sound of things)

Jesse Naugher
Thanks Jesse ... it was one of those things were you are "brain-crapped" and when you come back and look at it next morning, its that stupid statement [appDelegate release] ... thanks to being "overly" good memory citizen :) ... sorry for wasting your time, but if it helps, your conviction that it does return the same singleton object made me step through the debugger once again with a different perspective and thats when I spotted it :) ... Also having tabBarController in UIWindow did feel the right way to do it and am glad it worked out without any hacks or compromising the design :)
Dev