我想重新加载选项卡控制器(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];
}
正确的方法是将任何需要刷新的 VC 添加为某个 NSNotificationCenter 通知名称的观察者。一旦 VC 收到此消息,只需调用一个选择器即可[self setNeedsDisplay]
.
将 VC 添加到 NSNotificationCenter:
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(setNeedsDisplay) name:@"ViewControllerShouldReloadNotification" object:nil];
别忘了打电话removeObserver:self
当视图控制器被释放时。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)