【发布时间】:2012-07-01 15:17:21
【问题描述】:
参考我的问题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];
}
我的问题是:
它(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的视图 当应用程序进入活动状态时,我是否需要做一些事情,比如刷新以前的视图。然后通过检查会话来填充适当的视图。
提前致谢
【问题讨论】:
-
在方法调用之后释放 XTabViewCon 是不是很危险?
-
我通过将 release stmt 移动到 dealloc 方法来检查它。成功。 :) 你可以把它作为一个答案。我会接受
标签: ios pushviewcontroller application-state