切换和隐藏 TabBarItem
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,你的方法对我来说似乎并不是最幸运的方法。
您可以做的是将
UITabBarController
替换为UINavigationController
并采用以下方法:[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 aUINavigationController
and go with the following approach:[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.