Load the root view when app enter into background in iPhone sdk - iphone

I am developing an application which has 4 views and use navigation controller to navigate through. The first view is login interface. I just want to display login view when user press home button from second view. I have tried to use popToRootViewControllerAnimated in applicationDidEnterBackground. This does not work. Because I need to do this job only user press home button from second view (Second view contains MKMapView).
Can you please let me know what is the best option for this job? Basically I just need to check what view I am currently on.
Many Thanks

You could log a BOOL variable that the viewDidAppear function on your second controller sets to YES. And when you leave that view set it to NO. In applicationDidEnterForeground check it. If it is YES then the user left while in the second view.

Related

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.

IPhone sdk Login Control Segue issue

Hi I am new to Iphone Development and using iphone sdk5.
I am trying to implement an application through which I can login and show my application if login is successful, otherwise show the error alert.
problem which I am facing right now is that I have first view as View controller and I want to send the login details through clicking the login button and I want to perform the Segue through the same button if the Login is success full and show my TabBar Application. I have tried to implement basic push Segue as well as Custom segue... someway I was able to do through custom segue by checking the if(Flag)..then perform the segue... but the point is that I set the flag when i see the login is correct otherwise it should not set the Flag... now when I run the application I have to click the button twice and then the segue is performed and I get to my application TabBarController..
Please share some alternate ways also if you have better suggestions for me...
Any Ideas... please answer as soon as possible..
Thanks for time
The best method I can think of is:
You can ctrl-drag from the First view controller to the Second view (tab view controller). [You can use the view controller object at the bottom of the scene to do this.]
Create a identifier for the segue which was created, on the right hand side.
Define a IBAction for your Login button
Inside the IBAction do your FLAG checks
If the condition is TRUE then you call the
[self performSegueWithIdentifier: #"identifier_name_you_gave" sender:self];

Reload View only when application is opened Again

My application has tab bar with one of the tabs having a segmented control on navigation bar.
Based on segment clicked different view is displayed using a url.
I am calling the url in viewdidload method.I do not want to use viewwillAppear to call the url as it will be called each time the view is displayed.
I only want to call the url again whenever user closes the application and comes back.
Whats the best way to do this.Should I remove the view controller from and reload it again once the application is opened.
Please use a more descriptive title for your question next time!
There are notifications for this that you can observe in your application:
UIApplicationDidBecomeActiveNotification and UIApplicationWillEnterForegroundNotification come to mind.

Putting an ad always at the front on iPhone?

I want to put an ad on my iPhone application.
And I'm using TabBar to separate some features.
Here's my question. I just want to put ONE AD which always should be displayed no matter what user select & switch between views by pressing tab-bar. I want that ad right above the tab-bar.
I don't want to put ad on every view nor refreshed every time user changes view.
Can somebody give me some idea??
thanks.
Your TabBarControllers view was added to the application window at some point. This is usually in your applicationDidFinishLaunching method if doing it by code, otherwise it is done through Interface Builder. Either way, if you want to add a view globally, do it at the end of applicationDidFinishLaunching and add it as a subview of the application window, not to any individual view controller. Just ensure you are adding it after the tab bar controller as otherwise it will be covered up.