go to home screen of the iphone app after coming from background - iphone

I am trying to find out how should i take the user to the home screen of my app, after he comes back from the background.
I don't want to take the user to the home screen all the time when he is coming from the background.
But only when he clicks "view" on my push notification alert and the app was in the background at that time, i want to take him to the home screen.
But if he is opening the app from the background in general he should go where ever he was left off last time he clicked on the home button and went to background
Any help is appreciated.
Thanks,
Yogesh

There one bool property in info.plist--Application does not run in background
you should change that according to your requirement.

Ok i am not sure if this right way of doing it or not, but this is what i did, as my application have a tabbarcontroller the first thing that i did is i implemented the delegate method of the tabbarcontroller "didSelectViewController"
// By doing this every time you select a tab it will come back to the rootViewController of that tab
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
if ([viewController isKindOfClass:[UINavigationController class]]){
[(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
}
}
and then on didReceiveRemoteNotification
if(tabBarController.selectedIndex == 1){
UINavigationController *navigationController = (UINavigationController*)tabBarController.selectedViewController;
[navigationController popToRootViewControllerAnimated:NO];
[[[navigationController viewControllers ] objectAtIndex:0]viewWillAppear:YES];
}else{
self.tabBarController.selectedIndex = 1;
}
so let me explain what this is doing, it is checking if the current tab is 1 if it is then it will remove all the view from the navigation stack to bring the view to the root view, if the current tab is not 1 and just make it to 1.

Related

Back button animation issue in iPhone

I have scenario in that, On click of Tab I am calling viewWillAppear method and but after that when I press Back button It will directly back without any animation.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
switch(mytabbar.selectedIndex)
{
case 0:
[viewController viewWillAppear:YES];
break;
}
}
All thing working fine but I don't get Back button animation is only issue
You are not allowed to call view controller life cycle methods - like viewWillAppear and viewDidLoad. They automatically called throughout the life cycle of a view as and when needed and applicable.
You need to tell us what exactly you want to implement , then we can help you?
On click of back:
- (IBAction)onBackButtonClicked:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}

pop one or more viewControllers when app enters in foreground

My app downloads data from internet when it starts, during the splash screen.
It does the same when, from the background, it enters in foreground (when the user open the app from the background).
When the app is open, the user can push some views in order to read the informations downloaded.
I want that when the app is open from the background state, the viewControllers are popped until the first view is showed...
I want to do something like this in my AppDelegate:
while ([self.view isNotMainView]) //of course this method doesn't exists
{ [self.navigationController popViewControllerAnimated:NO]; }
is it possible?
Thanks
Just use:
[self.navigationController popToRootViewControllerAnimated:NO];
Hope that Helps!
hope Following link will help...
How are people popping their UINavigationController stacks under a UITabBarController?
You can keep a reference or Current navigation controller in your appdelegate OR you can write this in you viewDidUnload OR viewWillDisapper for popping navigation to root when application goes to background.
You could just compare the view against your main view if you have a reference hanging around:
while (self.view != myMainView)
etc. (Assuming that self.view is the correct reference as well.)

UITabBarController Weirdness ?

If I normally load up a UITabBarController and switch between views, it calls the viewWillAppear of each view controller.
But it is not so.
I want to switch to another tab as soon as another tab is touched.
If I specify a tab to load up - for example [self.tabBarController setSelectedIndex:0] in the viewWillAppear of one of the tabs (say tab 4)... It goes immediately back to tab 0.
But after that.... it does not call the viewWillAppear on any of the tabs when I switch between them.
For example, if I again go to tab 4, it does not come back to tab 0. I expect it to by a never ending cycle as I expect tab 0 to load up as soon as tab 4 is touch.
But it runs JUST ONCE !!
Why ??
Note: Question has been edited.
I think I found a solution. It works every time you click on your tab and it calls viewWillAppear on both tabs.
You can do this in your AppDelegate (or somwhere else in UITabBarController's delegate):
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
Sample code:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if([self.tabBarController.viewControllers indexOfObject:viewController] == 1) {
[self.tabBarController setSelectedIndex:0];
}
}
setting the selectedIndex won't change the selectedViewController. You will have to change selectedViewController itself. Look at the documentation for more details.

iphone - Modal view controller disappears?

So let's say I have a viewController named homeViewController, and another view controller named listViewController
I display listViewController on top of homeViewController as a modal.
If the user clicks the off button, and then comes back to the app the modalViewController is gone.
ListViewController *listViewController = [[ListViewController alloc] init];
[self presentModalViewController:listViewController animated:NO];
[listViewController release];
Note: Application doesn't startup from scratch when this occures and the previous state is still visible
I'm assuming that by "off button" you mean the user locks the iDevice.
I just tried this in one of my apps and the modal view controller is still there after unlocking. My guess would be that it's something unrelated to the code you have posted. I would check your - (void)applicationWillResignActive:(UIApplication *)application method in your app delegate class and see if there's anything there that would dismiss the modal view controller.
Here is what the problem was.
When the user locks the screen I remove homeViewController from window
[homeViewController removeFromSuperview];
When user starts the app again I do
[windows addSubview:homeViewController];
that brings homeViewController on top of its modeal

ModalViewController goes to background on application start

I am migrating my app code base to iPhone SDK 4. In one of the screens I use
-(IBAction) LoadSearch {
MySearchViewController *mySearchController=[[MySearchViewController alloc] initWithNibName:#"MySearchViewController" bundle:nil];
[self.navigationController presentModalViewController:mySearchController animated:YES];
}
That launches the ModalViewController. While the Modal is open, if the user clicks home button, the application goes to suspended state.
If I relaunch the application, immediately after launch the Modal becomes invisible. It seems like the Modal goes to the background of navigationController views.I can see the modal when I rotate the iphone to landscape mode (the modal is being rotated appropriately).
Has any one seen this issue before? Any suggestions are appreciated.
Solved this issue my self.
I was calling the [window addSubview:tabBarController.view] in applicationDidBecomeActive.
So, this resulted in adding tabBarController.view to the window and any modalViewControllers are pushed to background.