如何重新加载 UIViewController
答案:1 悬赏:10 手机版
解决时间 2021-01-26 04:35
- 提问者网友:寂寞撕碎了回忆
- 2021-01-25 06:24
如何重新加载 UIViewController
最佳答案
- 五星知识达人网友:山有枢
- 2021-01-25 07:45
我想要重新加载 tabbar controller(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];
}
解决方法 1:
正确的方法来执行此操作将添加任何需要刷新到某些 NSNotificationCenter 通知名称以观察员身份的 VC。一旦 VC 获取此消息,只是调用一个选择器,调用 [self setNeedsDisplay] 。
将一个 VC 添加到 NSNotificationCenter:
[[NSNotificationCenter defaultCenter] addObserver:self selector @selector(setNeedsDisplay) name:@"ViewControllerShouldReloadNotification" object:nil];
别忘了打电话给 removeObserver:self 视图控制器时被释放。
- (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];
}
解决方法 1:
正确的方法来执行此操作将添加任何需要刷新到某些 NSNotificationCenter 通知名称以观察员身份的 VC。一旦 VC 获取此消息,只是调用一个选择器,调用 [self setNeedsDisplay] 。
将一个 VC 添加到 NSNotificationCenter:
[[NSNotificationCenter defaultCenter] addObserver:self selector @selector(setNeedsDisplay) name:@"ViewControllerShouldReloadNotification" object:nil];
别忘了打电话给 removeObserver:self 视图控制器时被释放。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯