我想重新加载标签栏 Controller (UIViewController)中包含的所有 View 。搜索后我发现我必须应用 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];
当 View Controller 被释放时,不要忘记调用 removeObserver:self
。
关于iphone - 如何重新加载 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12382981/