iphone app with uinavigationcontroller and uitabbarcontroller - ios

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 check 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

Related

How do I make the login screen with the main tabview controller that makes it open the first time the app is opened

Link to image here
This is the view of the screens
I want
I can't link it to the main tab bar controller
Give the nav controller that parents the login screen a storyboard identifier. Next, create a custom UITabBarController subclass and assign it to the Tab Bar Controller. In its viewDidAppear method, check to see if you need to log in. If so, instantiate the login nav controller via its storyboard ID and present it modally.
Set your login screen as initial view controller. You can set view controller as initial view from attribute inspector. When user login's successfully, present your main tab view controller.

Launch a viewcontroller in a stack of tabbar controller from background (iOS-Swift)

I have a storyboard with tab bar controller and one of the tabs segue to another view controller and so on as show in the picture.
I want to go to the page (3) programmatically in the stack while maintaining the stack of the tab bar controller .
Thanks in advance..enter image description here
This one's a little tricky, maybe someone else here knows a better way of doing it but here's how I would tackle the problem. Let's assume for simplicity that all views are loaded already. Let me know if this works
Setup an observer in the view controller that is being displayed by the tab selected in the tab bar controller. (Let's call this page TabPageVC). When the event that the TabPageVC is observing is fired have it segue way to page 3 immediately
In app delegate when the app becomes active / enters foreground check to see if you need to display page 3. If you do need to then get the root view controller in app delegate (i'm assuming it's the tab bar view controller, if it's not you'll need to set it to be).
Set the selected tab in the tab bar controller to be the tab of the index that TabPageVC lives in
Trigger that event that TabBarVC is observing this will cause TabBarVC to immediately segue way to page 3 and you'll have retained the stack

How a Page View Controller can pause the Root View Controller from running. (xcode)

My app starts with a View Controller (Initial). On this View Controller i display a countdown message (using NSTimer and scheduledTimerWithTimeInterval) that is auto-initiated when the user opens the app (viewDidLoad method).
In the settings menu (a second View Controller (modal segue to the initial) a have a "Tutorial" menu choice that leads to a Page View Controller that handles a couple of View Controllers and presents them as Form Sheets). The last page of this Page View Controller has a button "OK" that dismisses the Page View Controller (so that brings you back to the Settings menu according to my Storyboard).
So far, so good.
Now when the user runs the app, i call from my initial View Controller the viewDidAppear method and using NSUserDefaults i run a check if this is the first time the user runs the app. If YES it creates an instance of the Page View Controller that displays (as form sheet) the Tutorial. And here is my problem..The initial View Controller is running at the background as expected to do so.. but how can i pause the countdown message until the user dismisses the Tutorial (by pressing the OK button)?
NOTICE: I've just noticed that if you change the page view controller
presentation as "Full Screen" or run the app on the iphone instead of
the ipad (forced full screen presentation) the app is running normally, but that,i
assume, is because in this case (full screen presentation) the initial
view controller won't load until the page view controller is being
dismissed!
I think that your PageViewController has a reference to his parent view controller (InitialViewController), so you have to define your NSTimer as a InitialViewController property.
You can use global app notification system to let know your rootViewController about external events. Check out NSNotificationCenter class reference.

How to segue to a view managed by Navigation Controller?

I am working working on an app (iOS 5+) that contains a stacks of views that are managed by a navigation controller:
MyNavController -> MyRootViewController -> MyTableViewController -> MyDetailViewController
I also have view controllers that are not managed by the navigation controller for handling the login (LoginViewController) and registration (RegViewController) of the app.
When the app is launched, it will check if an account has been created. If so, it will seque to the LoginViewController for user login, and then it will segue to MyRootViewController. However, if no login is detected, the user will be presented with the RegViewController scene to create an account. Then, I would like to take the user directly to the MyTableViewController scene, bypassing the RootViewController scene. Is this possible (via Storyboard or programatically)? I have attempted to define a modal segue from RegViewController to MyTableViewController, which seems to partially work - it is able to go to the scene but with the nav bar missing on top of screen. But when I select a table item it fails to go to MyDetailViewController. It crashes with error "Push segues can only be used when the source controller is managed by an instance of UINavigationController."
Any advice?
Thanks in advance.
Select your MyDetailViewController. On the top select editor->embed in ->navigation controller.

About tab bar using storyboard

I want to create an app using storyboard that has login window and tab bar controller.
So the flow will be upon tapping the login button, the app will be redirected to tab bar controller with its views.
I have done this:
But referring to Apple Documentation: UITabBarController
Because the UITabBarController class inherits from the
UIViewController class, tab bar controllers have their own view that
is accessible through the view property. When deploying a tab bar
interface, you must install this view as the root of your window.
Unlike other view controllers, a tab bar interface should never be
installed as a child of another view controller.
So that means I am not allowed to do so?
In addition:
The 3 views that are referred by my tab bar, then each of them has their own child view again, but the tab bar in the child view is gone. What could be happen? Am I missing something?
What I have done in all my apps that are structured similarly is to have the first view controller check for valid authentication and if that fails, present a login VC. That login VC has a delegate defined that will pass back the user credential after a successful login and then dismisses the modal login VC does whatever.
Here is a sample layout:
The delegate protocol looks like this:
#protocol LoginViewControllerDelegate
-(void)finishedLoadingUserInfo:(UserInfo *)curUser;
#end
Where UserInfo is the model I use for the user information (in my case, NetworkID, FullName, etc).
When the user has successfully authenticated, I fire off that delegate method which is handled in the class that presented it. If you need more detail, I can help - but the process is simple.
You can launch your login screen first from the appDelegate and then setup and launch the tabBarViewController after the login is successful.
An alternative design is to do the following steps:
1. set up your tabBarViewController,
2. disable the tabs,
3. launch your login view controller modally,
4. enable tabViewController tabs
Either of these two approaches should work.

Resources