iphone - 如何重新加载 UIViewController

标签 iphone ios xcode ios4 iphone-sdk-3.0

我想重新加载标签栏 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/

相关文章:

ios - Xcode JSON字符串接收数据

iphone - 完成播放后,简单的音频引擎isBackgroundMusicPlaying仍为YES

iOS View Controller 在旋转后移动

ios - 如何从 Apple Watch 获取传感器数据到 iPhone?

ios - Obj-C - 带有图像的数组上的if语句

ios - 如何强制后退按钮转到第一个 View Controller (swift)

iphone - iOS 5 - CTCallCenter 不适合我

iphone - 如何在ios中获取州,国家列表

iphone - iOS App 的系统设置是否可以通过 Enterprise Distribution 配置?

swift - 如何在 Xcode 源代码编辑器扩展中获取当前工作区路径?