Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS应用程序将进入前台,它会停留一段时间_Ios_Uiapplicationdelegate_Background Foreground - Fatal编程技术网

iOS应用程序将进入前台,它会停留一段时间

iOS应用程序将进入前台,它会停留一段时间,ios,uiapplicationdelegate,background-foreground,Ios,Uiapplicationdelegate,Background Foreground,我添加此功能是为了在应用程序进入前台时发布通知: - (void)applicationWillEnterForeground:(UIApplication *)application { [[NSNotificationCenter defaultCenter] postNotificationName: @"UIApplicationWillEnterForegroundNotification" object: nil]; } 在我自己的课堂上: - (void) handleE

我添加此功能是为了在应用程序进入前台时发布通知:

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[NSNotificationCenter defaultCenter] postNotificationName: @"UIApplicationWillEnterForegroundNotification" object: nil];
}
在我自己的课堂上:

- (void) handleEnterForeground: (NSNotification*) sender
{
    [self reloadTableData];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(handleEnterForeground:)
                                             name: @"UIApplicationWillEnterForegroundNotification"
                                           object: nil];
}
但是handleEnterForeground:函数将调用两次,我不知道为什么。这个 reloadTableData:函数将调用远程webService,因此当应用程序进入
前台,它将被卡住一段时间。

系统将自动调用该事件。它触发两次的原因是您再次手动触发它

另外,最好使用变量名UIApplicationWillEnterForeground,而不是NSString文本


编辑:我现在意识到困惑来自于这样一个事实:你不知道这个名字已经被取了。作为对遇到此类问题的其他人的提醒,最好在事件名称前面加上项目前缀(即XYZEVENTNOTITION),以避免冲突。

我确定我调用了该函数一次。@cnu他调用了一次,iOS运行时调用了一次。此活动将自动调用。谢谢,现在一切正常!!!我把“UIApplicationWillEnterForegroundNotification”改成了另一个词。与其改成另一个词,不如把代码去掉,然后使用自动发生的事件?他的名字是Borrden,不是OLO。