我添加此功能以在应用程序进入前台时发布通知:
- (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 文字。
编辑:我现在意识到混乱来自于你不知道这个名字已经被占用了。对于遇到此类问题的其他人来说,最好在事件名称前加上项目前缀(即 XYZEventNotification)以避免冲突。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)