xcode 如何重新加载 UIViewController
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12382981/
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 reload UIViewController
提问by Shubham Sharma
I want to reload all the views contained in tabbar controller(UIViewController).After searching I found that I've to apply setNeedsDisplay Method but I am not able to get where should I apply it.Any other alternatives are also welcomed
我想重新加载 tabbar 控制器(UIViewController)中包含的所有视图。搜索后我发现我必须应用 setNeedsDisplay 方法,但我无法找到我应该在哪里应用它。也欢迎任何其他替代方案
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
.....
.....
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self customToolbar];
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
-(void)customToolbar
{
//Declared view controllers and their Navigation Controller
.....
//Declared tab bar items
.....
tabBarController = [[GTabBar alloc] initWithTabViewControllers:viewControllersArray tabItems:tabItemsArray initialTab:1];
}
采纳答案by Stavash
The correct way to do this would be to add any VC that needs to be refreshed as an observer to a certain NSNotificationCenter notification name. Once the VC gets this message, just call a selector that calls [self setNeedsDisplay]
.
执行此操作的正确方法是将需要作为观察者刷新的任何 VC 添加到某个 NSNotificationCenter 通知名称。VC 收到此消息后,只需调用一个选择器即可[self setNeedsDisplay]
。
To add a VC to NSNotificationCenter:
将 VC 添加到 NSNotificationCenter:
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(setNeedsDisplay) name:@"ViewControllerShouldReloadNotification" object:nil];
Don't forget to call removeObserver:self
when the view controller is deallocated.
不要忘记removeObserver:self
在视图控制器被释放时调用。