如何重新加载UIViewController [英] How to reload UIViewController

查看:1820
本文介绍了如何重新加载UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重新加载tabbar控制器(UIViewController)中包含的所有视图。搜索后我发现我要应用setNeedsDisplay方法,但我无法在哪里应用它。还欢迎其他任何替代方案

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

- (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] 的选择器。

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:

To add a VC to NSNotificationCenter:

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

别忘了拨打 removeObserver:self 取消分配视图控制器时。

Don't forget to call removeObserver:self when the view controller is deallocated.

这篇关于如何重新加载UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆