切换和隐藏 TabBarItem

发布于 2024-09-15 05:50:16 字数 519 浏览 4 评论 0原文

我有一个 iPhone 应用程序,设置如下:

  • UITabBarController
  • CustomViewControllerLogin (UIViewController)
  • UINavigationController
    • 自定义ViewController1(UIViewController)
    • 自定义ViewController2(UIViewController)
  • CustomViewControllerLogout (UIViewController)

当用户单击 CustomViewControllerLogin 上的登录按钮时,如何切换到 CustomViewController1?

我还需要“隐藏”CustomViewControllerLogin 和“显示”CustomViewControllerLogout?

提前致谢!!! 贾森

I have an iPhone application that is setup as follows:

  • UITabBarController
  • CustomViewControllerLogin (UIViewController)
  • UINavigationController
    • CustomViewController1 (UIViewController)
    • CustomViewController2 (UIViewController)
  • CustomViewControllerLogout (UIViewController)

How do I switch to CustomViewController1, when the user clicks the Login button on CustomViewControllerLogin?

I also, need to "hide" CustomViewControllerLogin and "show" CustomViewControllerLogout?

Thanks in advance!!!
Jason

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

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

发布评论

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

评论(1

嘿哥们儿 2024-09-22 05:50:17

好吧,你的方法对我来说似乎并不是最幸运的方法。

您可以做的是将 UITabBarController 替换为 UINavigationController 并采用以下方法:

  • 以模态方式显示您的 CustomViewControllerLogin。您可以使用如下内容:

[self.navigationController PresentModalViewController:instanceOf CustomViewControllerLoginanimated:YES];

  • 将 navigationController 中的 rootViewController 设置为您的 CustomViewController1

  • 在您的 CustomViewControllerLogin 中,一旦登录成功,请使用以下命令关闭 CustomViewControllerLogin:

[selfmissModalViewControllerAnimated:YES]

  • 当执行时,您的 CustomViewController1 将被显示。在这里执行您的应用程序逻辑并有一个“注销”按钮。您可以将其放在导航栏上,例如右侧。

  • 当用户点击此注销按钮时,您将执行与登录时相同的操作:

[self.navigationControllerpresentModalViewController:instanceOfCustomViewControllerLogoutanimated:YES];

我见过很多应用程序,其中 UITabBarController 被滥用于其不想要的目的。例如,请参阅这篇文章。

Well, your approach doesn't seem to be the most fortunate one to me.

What you could do is to replace the UITabBarController with a UINavigationController and go with the following approach:

  • present your CustomViewControllerLogin modally. You can use something like this:

[self.navigationController presentModalViewController:instanceOf CustomViewControllerLogin animated:YES];

  • set the rootViewController in the navigationController to be your CustomViewController1

  • in your CustomViewControllerLogin, once the login is done successfully, dismiss the CustomViewControllerLogin using the following:

[self dismissModalViewControllerAnimated:YES]

  • when this gets executed, your CustomViewController1 will be displayed. Do your app logic here and have a "Logout" button. You could put it on the navigation bar, on the right side for example.

  • when the user taps on this logout button, you do the same as you did for the login:

[self.navigationController presentModalViewController:instanceOf CustomViewControllerLogout animated:YES];

I have seen a lot of apps where the UITabBarController is abused for purposes that it wasn't intended for. See for example this article.

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