从主屏幕重新打开应用程序时如何刷新标签栏内容?(iOS / Xcode)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8853060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to refresh tab bar content upon reopening the app from home screen? (iOS / Xcode)
提问by Fitz
for all of my view controller.m I have the majority of my code in:
对于我所有的视图 controller.m,我的大部分代码都在:
- (void)viewDidAppear:(BOOL)animated
So, each time I switch between tab bars all of the info in each view refreshes. (which is good!) Although, when I open the app from the home screen the tab won't update...I have to switch to another tab and back again to get it to load.
因此,每次我在标签栏之间切换时,每个视图中的所有信息都会刷新。(这很好!)虽然,当我从主屏幕打开应用程序时,标签不会更新......我必须切换到另一个标签并再次返回以加载它。
Any solutions?
任何解决方案?
回答by Bill Burgess
You need to sign up for a notifications to handle it. Register each tab for the notification and a method to handle it. Then just perform your viewDidAppear. It works like a charm.
你需要注册一个通知来处理它。为通知注册每个选项卡以及处理它的方法。然后只需执行您的 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];
}
}
回答by vampirewalk
Maybe you can invoke all your refreshing code in
也许你可以调用所有令人耳目一新的代码
(void)applicationDidBecomeActive:(UIApplication *)application
{
}
this method is in your AppDelegate.
这个方法在你的 AppDelegate 中。
回答by PopUp
Try putting this in the view controller's m file:
尝试将其放入视图控制器的 m 文件中:
- (IBAction)done:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}