2012-06-30 56 views
0

參照我的問題問Change Tab view after certain time interval received as response from Server request, 我用下面的代碼來顯示會話超時消息時應用涉及到激活狀態AppDelegate.mapplicationDidBecomeActive:未能推動相應的視圖

方法:

- (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的觀點,當應用程序涉及到激活狀態,我需要做的是這樣沖洗先前的觀點。然後通過檢查會話來填充適當的視圖。

在此先感謝

+1

在方法調用之後立即釋放XTabViewCon是危險的否? – Pierre

+0

我通過將release stmt移到dealloc方法來檢查它。成功。 :) 你可以把它作爲答案。我會接受 –

回答

0

釋放XTabViewCon剛過你的方法調用是危險的不是嗎? 您必須確保在發佈之前您沒有使用您的對象。