iOS以编程方式显示基于当前用户的视图控制器 [英] iOS Programmatically display a view controller based on current user

查看:35
本文介绍了iOS以编程方式显示基于当前用户的视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PreferencesViewController ,其中显示了有关当前用户的信息:

但这取决于当前用户.如果用户尚未登录,我会触发对 PreferencesViewController viewWillAppear 方法上的 LoginViewController 的选择:

当用户尚未登录并在 Preferences 选项卡上再次点击时,就会出现问题.它将安全退回到 PreferencesViewController ,从而导致意外行为( PreferencesViewController 仅应在用户登录后呈现)

解决此问题的最佳方法是什么?我使用的方法还可以吗?可以更优化吗?

解决方案

您应该实现委托方法tabBarController:shouldSelectViewController :,如果用户尚未登录,则返回NO.

I have a PreferencesViewController that shows information about current user:

But it depends on the current user. If the user hasn't logged in yet, I am triggering a segue to LoginViewController on PreferencesViewController viewWillAppear method:

The problem comes when the user hasn't signed in and taps again on the Preferences tab. It unwinds the segue back to PreferencesViewController, causing unexpected behaviour (PreferencesViewController should only be rendered when the user has logged in)

What is the best way to solve this? The approach I am using is okay? Can it be more optimal?

解决方案

You should implement the delegate method, tabBarController:shouldSelectViewController:, and return NO if the user hasn't signed in.

这篇关于iOS以编程方式显示基于当前用户的视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆