Shu*_*rma 6 iphone xcode iphone-sdk-3.0 ios4 ios
我想重新加载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];
}
Run Code Online (Sandbox Code Playgroud)
正确的方法是将任何需要刷新的 VC 添加为某个 NSNotificationCenter 通知名称的观察者。一旦 VC 收到此消息,只需调用一个调用 的选择器即可[self setNeedsDisplay]。
将 VC 添加到 NSNotificationCenter:
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(setNeedsDisplay) name:@"ViewControllerShouldReloadNotification" object:nil];
Run Code Online (Sandbox Code Playgroud)
不要忘记removeObserver:self在视图控制器被释放时调用。
| 归档时间: |
|
| 查看次数: |
12187 次 |
| 最近记录: |