如何重新加载UIViewController

我想重新加载包含在tabbar控制器(UIViewController)中的所有视图。search后,我发现我必须应用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得到这个消息,就调用一个select器来调用[self setNeedsDisplay]

要添加一个VC到NSNotificationCenter:

 [[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(setNeedsDisplay) name:@"ViewControllerShouldReloadNotification" object:nil]; 

当视图控制器被释放时,不要忘记调用removeObserver:self