Return to a removed view controller - iphone

Here is the situation, I have a login page as the initial rootView of a tab bar. Once the login process is done, the view is removed from the navigation controller, so you don't navigate back to it. I have places in the app where you can logout. The logout process works fine, but when I try to forward the user back to the initial login view (the one we removed) from inside the same tab bar item, I can't seem to reset the view controller stack to contain only the desired element. Is this a question of where I am changing the view? It just doesn't seem to remove the current view. I have tried alot of stuff, popto, popview, and many others, and nothing seems to work properly. Has anyone had to deal with this?

Take a look at the View Controller Programming Guide and the various way to alter the navigation stack (push, pop, set, etc).

Look into making your login view controller into a modal view controller, which pops up when credentials need to be entered.
A modal view controller is perfect for view controllers that you don't need to keep around, but which can be needed at different points in your application usage "flow".
Laurent's link will explain to you what the different options are for a navigation stack, and Apple's document suggests contexts in which those different view controller types are useful. I highly recommend reading it.

Related

Using a Navigation Controller, Page View Controller, and a Tab Bar Controller

I've fairly new to Swift and I've been reading a lot of answers to questions but I'm still struggling to figure this out. For what I'm building, I want the option to swipe between three main pages but I also want a tab bar that serves as an index and another option to navigate between the three pages. Currently I have three main pages that are each embedded in individual navigation views which are embedded in a page view controller. I tried simply adding a tab bar for each of the pages but that doesn't seem very practical. I was reading on orders of embedding but it doesn't seem to be what I want. How would I go about doing this? Thank you!
sounds like a lot of hierarchy but maybe you can try this
Have a single UIViewController that holds your page view controller. Build a custom uiview guy that holds three buttons which will serve as your tab bar and pin it to the bottom of this UIViewController.
For your page view controller, you can proceed as normal and have it hold 3
children. You'll need proper delegation with protocols from: custom tab bar > uiviewcontroller to tell him to move the pages around.

Logout issue in TabBar based app

This is quite a common question, but after trying a lot to fix the issue, finally I have decided to post it on StackOverFlow.com
I have a tab bar based app. The tab bar is loaded in AppDelegate.m as follows:
self.tabBarController.viewControllers = #[viewController1, viewController2 , viewController3 , viewController4 , viewController5];
My 5th tab has a button for logout. When user clicks logout, I want to clear/reset entire app and go to login page which is a modalviewcontroller.
I have tried following while logging out:
NSMutableArray * vcs = [NSMutableArray
arrayWithArray:[self.tabBarController viewControllers]];
[vcs removeAllObjects ];//ObjectAtIndex:4];
[self.tabBarController setViewControllers:vcs];
This removes all views from tab-bar. But when I login again, nothing is displayed. I want to show my home screen, i.e. tab item 1 selected by default.
I have read that its not a good practice to call didFinishLaunchingWithOptions again manually.
Is there a way where I can reset all tab-bars and reinitialise them again ?
This will help me solving one more problem that is linked with this situation. When user logs out and log in again, and view controllers are not cleared, then logout page is shown again after login. And not the home view controller.
Please help.
Thanks in advance.
If you really want to start over, you should put a method, lets call it -(void)setupTabBarController, in the app delegate, and at start up you would call it from application:didFinishLaunchingWithOptions:. Later when you want to reset, call that method again from the login page. This method would have the creation of all the tab bar controller's view controllers in it, as well as setting the tab bar controller as the root view controller of the window.
However, it's not really clear that you need to do this, depending on what state all those controllers are in at logout time. Your problem with the logout page being shown again could probably be fixed in a simpler way.
Well, nothing is showing because you removed the views and never added them back in.
There is no need to remove the view controllers from the tab bar after you log out. You can just write a method to reset all the data in each view controller and then set the selected tab to what you desire.
I know, this is not really an answer to your question, but this could maybe help you too (and as I can't comment on post yet i have to post it like this :)).
I had some problems with "resetting" the navigation stack when the user logs out in my tabbar app too. In the beginning I had my tabbar-controller as the root controller and was displaying the login-screen modally but than it was quiet hard reset the navigation stack once the user loged out.
What I ended up doing and it works for me quiet well is, I set the login controller as root controller and after log in displayed the tab navigation modally. On log out I simply dismiss the tabbar-controller again - everything starts from the beginning again.
Maybe you could try this and see if it is easier to handle.
You should be add tabBar controller on second view controller. main view controller show home screen. when you navigate second view controller then you add tabBar here.

Xcode - Manually load a view controller

What I am asking may be impossible and sound weird, but here it goes.
Here is similar to what I want to achieve:
A user opens the app for the first time, there are two tab bars, in the first one (he has not tapped the second one yet) he presses a button that should initiate a progress view and text view changes and other view changes EVEN THOUGH the user has not loaded the other view controller by clicking the second tab bar.
So, is there a way to generally load a view controller before the user manually loads it himself, I know calling viewDidLoad manually will not help, any suggestions? Pretty confusing, it is like modifying a view but the controller has not loaded yet...
Thanks!
Make the changes in the other view controller and then let the controller configure its own view when it does its natural loading.

UINavigationController containing a UITableView, then a UITabBarController with more UITableView's

Sorry for the vague title!
I am trying to achieve the following functionality: A user is first presented with a UINavigationController containing a UITableView. When the user taps a cell in the table view, I want to push a new view which contains a UITabBarController (that'll stay visible regardless of the currently visible UIViewController) and a UITableView again, that people can again select a cell from and which will then again push to UINavigationController.
If a user selects a tab from the UITabBar, I want the first screen (without the UITabBar) to be the one that users can go back to, not the tab they just came from. Also, if a user selects one of the UITableView items on any of the tabs, I want the back button to go back to the previously displayed screen (as you'd expect with a standard UINavigationController)
I've spent hours trying to find the answer to this and I just can't anywhere! I hope I haven't been too vague or confusing in my explanation.
James.
If your desired UX is confusing to explain here, imagine how your users will feel! I would reconsider the intended design.
From the View Controller Programming Guide:
An application that uses a tab bar controller can also use navigation
controllers in one or more tabs. When combining these two types of
view controller in the same user interface, the tab bar controller
always acts as the wrapper for the navigation controllers. You never
want to push a tab bar controller onto the navigation stack of a
navigation controller. Doing so creates an unusual situation whereby
the tab bar appears only while a specific view controller is at the
top of the navigation stack. Tab bars are designed to be persistent,
and so this transient approach can be confusing to users.
That said, you can probably hack something close to what you are talking about but you'll need to write a bunch of code to handle the navigation using the UITabBarControllerDelegate and UINavigationControllerDelegate methods and keep track of whatever state you need to know where you want to navigate to based on a user action. Odds are you'll end up with something complicated to code, maintain, and worse, use.

UINavigation controller problem

I'm developing an iPhone application and I'm trying to do this:
I want an application with tree views. The view shown first, doesn't have a navigation bar. If the user tap on a button, I need to open the second view with a navigation bar and a table view. The user can also add new items to the table view. If the user do so, the application will show the third view where the user can add fields (this view has also a navigation bar).
It may seem simple, but for me it is not. I don't know how to use the UINavigationController and have not found yet a similar example for what I do (paragraph translated by google).
UPDATE
I don't know how where to put UINavigationController.
How can I do that? Can I use a UIViewController to call a UINavigationController?
Thank you.
take a look at the Recipes example (it also uses core data which may confuse things a little) http://developer.apple.com/iphone/library/samplecode/iPhoneCoreDataRecipes/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008913
There is also a simpler starting point here http://developer.apple.com/iphone/library/samplecode/TableViewSuite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007318 but the Recipe example covers just about everything you need.
EDIT:added the following
For the very simplest example use XCode to build a new application - a navigation based application (sorry, I'm in front of a PC today so that is from memory). That will give you a blank application with the navigation controller created. You then use the navigation controller to push and pop your view controllers
ViewController Programming Guide