0

In an application having UITabBarController, I want to implement following scenario:

When user is on 'X' Tab, he/she does something & then move to another tabs. And again he/she comes back to 'X' tab(say after 5minutes-> this is important as I may change 5min to 10min in future), then I want to show some message like your 'Session is expired'.

Whenever user comes back 'X' Tab, it need to make server request to get response code. Depending upon that I want to show the pop-up 'Session is expired'.

I thought following way to implement:

In every viewWillAppear: method of all views being loaded inside 'X' Tab viewController of UITabBarController I will make server request & check for response & perform operations accordingly.

But it will involve many server request which I want to avoid.

I am not able to conclude with solution. How can I achieve my requirement.?

Thanks a lot in advacnce.

hp iOS Coder
  • 3,230
  • 2
  • 23
  • 39

1 Answers1

0

You need to perform this only once in tab bar delegate method -

- (void)tabBarController:(UITabBarController *)tabBarController 
    didSelectViewController:(UIViewController *)viewController

Inside this method based upon the tab index you can have your code, you won't need to write the code in several view controllers.

rishi
  • 11,779
  • 4
  • 40
  • 59
  • Ohhhh... thanks a lot.. let me try this. I will surely accept your answer upon it works for me – hp iOS Coder Jun 28 '12 at 10:56
  • I tried it, but the delegate method is called only when user touches any of the tabs. What about all other `UIView`s that are pushed inside the `UINavigationController` of **'X' Tab**? For those views again I need to call the code I wrote for TabBArController inside `viewWillAppear`. – hp iOS Coder Jun 28 '12 at 13:44
  • For all those view also this will work, are you showing tab bar consistently through out the app, or you are hiding it some where? – rishi Jun 28 '12 at 13:55
  • No I am not hiding it at all. Now suppose application is on **'X' Tab** & goes to Inactive/Background running state. And when application becomes active then as I was on **'X' Tab** I want to make server request & want to check if application was inactive for more than 5 minutes – hp iOS Coder Jun 29 '12 at 04:50
  • Then for that scenario you can use - (void)applicationDidBecomeActive:(UIApplication *)application – rishi Jun 29 '12 at 04:56
  • yes I integrated that only. But again my question is I included the `UITabBarController` delegate method in AppDelegate.m, in one of the Tab's .m file & in **'X' Tab**'s .m file. I set the delegate for all of it. But after putting breakpoints only **'X' Tab**'s .m file `UITabBarController` delegate is getting called. Program control is not reaching to other .m file's delegate methods. – hp iOS Coder Jun 29 '12 at 06:27
  • 1
    you need o have all the code in appdegate.m where you have this tab bar delegate method, from there itself you can check. No need to have code in separate tabs – rishi Jun 29 '12 at 06:30