[英]How to reload UIViewController
我想重新加載tabbar控制器(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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.