0

我有一个应用程序,其中有 3 个选项卡来计算距离和所有。当我第一次启动该应用程序时,单击第三个选项卡时会发生一些网络呼叫。现在我把应用程序放到后台。当应用程序进入前台时,它应该调用 viewwillappear 再次进行网络调用。但它没有发生。它没有调用 viewwillappear。

如何检查应用程序何时进入前台,它应该检查第三个选项卡并调用网络方法

请帮我

4

4 回答 4

1

当应用程序进入前台时,

- (void)applicationWillEnterForeground:(UIApplication *)application;

应用程序委托的调用。

您可以在以下位置重新启动所有暂停的任务:

- (void)applicationDidBecomeActive:(UIApplication *)application;
于 2012-09-25T08:48:14.670 回答
0
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    //save in NSUserDefaults (or wherever) which tab is currently active
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // read from NSUserDefaults which tab was active before, 
    // and use an IF statement to control the further behavior
}
于 2012-09-25T08:48:01.953 回答
0
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    NSLog(@"%d",tabBar.selectedIndex);
    if (tabBar.selectedIndex == 2) {
        NSLog(@"Your work");
    }
}
于 2012-09-25T08:43:22.103 回答
0
- (void)applicationDidEnterBackground:(UIApplication *)application {
           if(tab3){
          [viewController3 netWorkCallFromHere];
    } 

}

在这种方法中,您必须在 Appdelegate 中声明 BOOL tab3。

在第三个 viewController 中将其设置为 true,并在另一个 viewController 中将其设置为 false。

当它从后台返回时,它将检查标志并相应地工作。

于 2012-09-25T08:57:35.400 回答