Change Tab view after certain time interval receiv

2019-08-23 03:17发布

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.

1条回答
爷的心禁止访问
2楼-- · 2019-08-23 03:21

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.

查看更多
登录 后发表回答