参考我提出的问题Change Tab view after certain time interval received as response from Server request, 我使用以下代码显示应用程序进入活动状态时的会话超时消息
AppDelegate.m中的方法:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// to check the session
XTabViewController *XTabViewCon = [[XTabViewController alloc] init];
[XTabViewCon pushViewUponCheckedSession];
[XTabViewCon release];
}
来自XTabViewController.m的方法
- (void)pushViewUponCheckedSession {
//THIS IS VERY IMPORTANT. IT CHECKS FOR SESSION
if ([[[ApplicationContext alloc] dataManager ] checkSession]) {
[self showSessionAliveView];
//here I can write something that will push a view that was seen last before leaving app to inactive state. May be NSNotification could help me
}
else {
[self showSessionTimeOutView];
}
}
- (void)showSessionTimeOutView {
//show activity indi
waitingIndicator = [[MyWaitingIndicator alloc]init];
[self.view addSubview:waitingIndicator];
[waitingIndicator setHidden:YES];
[waitingIndicator stopAnimating];
//push session timeout view
SessionTimeOutViewController *sessionTimeOutView = [[SessionTimeOutViewController alloc] init];
[[self navigationController] pushViewController:sessionTimeOutView animated:NO];
[sessionTimeOutView release];
[waitingIndicator release];
}
- (void)showSessionAliveView {
SessionAliveView *sessionAliveViewList = [[SessionAliveView alloc] init];
[[self navigationController] pushViewController:sessionAliveViewList animated:YES];
[sessionAliveViewList release];
}
我的问题是:
当我在Tabs之间切换时使用它(pushViewUponCheckedSession
)可以正常工作以检查会话是否过期。
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
//if X Tab is selected then & only then call this method
if (tabBarController.selectedIndex == 2) {
[XTabViewCon pushViewUponCheckedSession];
}
}
但它无法在checkedSession上显示SessionTimeOutViewController的视图 当应用程序进入活动状态时,我是否需要执行诸如刷新先前视图之类的操作。然后通过检查会话填充适当的视图。
提前致谢
答案 0 :(得分:0)
在你的方法调用之后释放XTabViewCon是危险的吗? 在释放之前,您必须确保没有使用对象。