iOS 标签栏控制器中的动态数据

发布于 2024-10-20 20:18:24 字数 553 浏览 1 评论 0原文

我在我的应用程序中使用标签栏控制器,但当应用程序首次启动时,我在控制器顶部加载一个登录屏幕:

initialScreenViewController = [[Login alloc] init];
[window addSubview:tabBarController.view];
[window addSubview:initialScreenViewController.view];
[window makeKeyAndVisible];
return YES;

当用户成功进行身份验证时,我删除登录视图:

[self.view removeFromSuperview];

这一切都可以完美运行,但有一个小例外。我的选项卡栏控制器的第一个选项卡上有一些标签,这些标签根据用户登录的内容进行填充。但是,由于该视图实际上在用户进行身份验证之前加载到登录屏幕后面,因此在身份验证后它不会正确显示。

我的问题是......有没有办法让标签栏页面在登录后如何“刷新”?或者甚至可能在登录后才加载标签栏控制器?

谢谢你!! 贾森

I am using a tab bar controller in my app but I load a login screen on top of the controller when the app first starts:

initialScreenViewController = [[Login alloc] init];
[window addSubview:tabBarController.view];
[window addSubview:initialScreenViewController.view];
[window makeKeyAndVisible];
return YES;

When the user successfully authenticates, I remove the login view:

[self.view removeFromSuperview];

This all works perfectly with one small exception. There are labels on the first tab of my tab bar controller that get populated based on what the user logs in with. However, since that view actually loads behind the login screen before the user has even authenticated, it doesn't appear correctly after authentication.

My question is this....is there a way to get the tab bar pages to some how "refresh" after login? Or perhaps not even load the tab bar controller until after login?

Thank you!!
Jason

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜声 2024-10-27 20:18:24

您可以通过多种方式解决这个问题,但我认为最简单的理解和实现是使用通知。让您的登录视图控制器在用户成功登录时发布通知,并让任何其他关心用户身份验证的视图控制器侦听该通知。

您希望登录控制器和其他任何东西之间有相当松散的耦合 - 可能根据用户状态更改其内容的视图控制器不应该特别了解有关登录控制器的任何信息,并且登录控制器也不应该知道了解可能受用户状态变化影响的所有其他控制器。通知提供了松散耦合,并且易于使用。

You could tackle this problem in a number of ways, but I think the simplest to understand and implement is to use a notification. Have your login view controller post a notification when the user has successfully logged in, and have any other view controller that cares about user authentication listen for that notification.

You want a fairly loose coupling between the login controller and anything else -- the view controllers that might change their content based on the user's status shouldn't have to know anything about the login controller in particular, and the login controller shouldn't have to know about all the other controllers that might be affected by a change in the user's status. Notifications provide that loose coupling, and they're easy to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文