iPhone viewwillappear在应用程序输入前台

时间:2012-09-25 08:40:58

标签: iphone viewwillappear

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

如何检查应用程序何时到达前台,它应检查第3个选项卡并调用网络方法

请帮帮我

4 个答案:

答案 0 :(得分:1)

当应用程序到达前台时,

- (void)applicationWillEnterForeground:(UIApplication *)application;
调用app委托的

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

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

答案 1 :(得分: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");
    }
}

答案 2 :(得分: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
}

答案 3 :(得分:0)

- (void)applicationDidEnterBackground:(UIApplication *)application {
           if(tab3){
          [viewController3 netWorkCallFromHere];
    } 

}

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

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

当它从后台返回时,它将检查该标志,它将相应地起作用。