对于我所有的 view controller.m,我的大部分代码都在:
- (void)viewDidAppear:(BOOL)animated
因此,每次我在标签栏之间切换时,每个 View 中的所有信息都会刷新。 (这很好!)虽然,当我从主屏幕打开应用程序时,选项卡不会更新......我必须切换到另一个选项卡并再次返回才能加载它。
有什么解决办法吗?
最佳答案
您需要注册一个通知来处理它。注册通知的每个选项卡和处理它的方法。然后执行您的 viewDidAppear。它就像一个魅力。
-(void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(becomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
-(void)becomeActive:(NSNotification *)notification {
// only respond if the selected tab is our current tab
if (self.tabBarController.selectedIndex == 0) { // Tab 1 is 0 index, Tab 2 is 1, etc
[self viewDidAppear:YES];
}
}
关于iphone - 从主屏幕重新打开应用程序时如何刷新标签栏内容? (iOS/Xcode),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8853060/