iphone app with uinavigationcontroller and uitabbarcontroller
I'm new to iphone programming and i'm trying to build an application that has a uinavigationcontroller and the rootviewcontroller is a uiviewcontroller that is basicly a login screen from the login screen the user moves to uitabbarcontroller that has 5 tabs and each tab is a uinavigationcontroller and each navigationcontroller has two button in the navbar one button brings a messages view and the other notifications view each view is a uiviewcontroller.
Now the user can press the message button on every tab and the message view will appear and i want to make sure that if he presses the button on the first tab and then goes to another tab then the message view will disappear and deallocated from memory and when he presses the message button on the new tab then another message view will appear.
I tried the create a single message view in the app delegate and every time that the user presses the message button to call a method from app delegate then in the method i ch开发者_JS百科eck which tab is pressed and push the view to the navigation controller that belongs to that tab but that doesn't work properly.
You can embed your login views inside the AppDelegate and show them as needed. From there you would load your rootController, which should be your tabBar. Then you can load up your navigation controller inside each tab. One for each tab. Your message view can be called from any of the tabs. Just need to make sure you layer your controllers the right way.
AppDel --> TabBar --> NavController --> Individual Views
Do you realize that you can replace the root view controller in a window? Your app delegate's -applicationDidFinishLaunching:withOptions:
method probably does something like:
window.rootViewController = loginViewController;
When you set the window's rootViewController
property, the window will add that view controller's view as a subview of itself.
There's nothing particularly special about -applicationDidFinishLaunching:withOptions:
-- it just happens to be the delegate method that's called when the app has finished loading and is ready to get down to business. You can set the window's rootViewController
property just as well from other methods, so when your login view controller determines that the user has successfully logged in, it can do something like one of the following:
- instantiate the tab bar controller and set the window's
rootViewController
property itself - send a message to its delegate (which would probably be the same object as the app delegate) to inform it that login was successful; the delegate could then install the tab bar controller
- broadcast a notification to tell anyone who cares that login was successful, and let someone else install the tab bar controller
精彩评论