在Swift中进行iOS登录/注销实现 [英] iOS Login / Sign Out Implementation in Swift

查看:304
本文介绍了在Swift中进行iOS登录/注销实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在swift中为iOS应用实现登录/注销流程。这是我的故事板 -

I've been attempting to implement a Login / Logout Flow for an iOS app in swift. Here's my storyboard -

在主视图控制器中(这是蓝屏),我实现了以下代码来检测用户是否已经登录,然后自动将它们带到表视图控制器 -

In the main view controller (which is the blue screen), I have the following code implemented to detect that if the user is already signed in, then to automatically take them to the table view controller -

覆盖func viewDidAppear(animated:Bool){

override func viewDidAppear(animated: Bool) {

    if PFUser.currentUser() != nil {

       self.performSegueWithIdentifier("test", sender: self)

    }

问题是,当我通过其中一个绿色屏幕登录或登录时,表格视图导航栏显示不同。当用户打开应用程序并且已经登录时,注销按钮会正确显示,但是,通过绿色屏幕登录或登录,导航栏包含'<返回'按钮。

The issue is, that when i Sign In or Login through either one of the green screens, the Table View navigation bar appears different. The 'Sign Out' button appears properly when the user opens the app and is already logged in, however, logging in or signing in through the green screens, the navigation bar contains a '< Back' button.

有人可以解释如何在故事板中以及在Swift中以编程方式实现登录/注销流程。我已经看到了一些Objective-C示例,但似乎无法在Swift中找到一个。如果有人有一个很好的例子,那将非常有帮助。

Can someone explain how a login / logout flow needs to be implemented in storyboard and programatically in Swift. I've seen some Objective-C examples out there, but can't seem to find one in Swift. If anyone has a good example, it would be really helpful.

推荐答案

<返回按钮出现,因为您正在执行从登录视图控制器到标签栏控制器的推送segue。应用程序更好的流程是让标签栏控制器成为您的初始视图控制器。然后,在其 viewDidAppear 方法中,检查用户是否已登录。如果用户未登录,则以模态方式将不带动画的信息传送到登录视图控制器。这一切都将在用户不注意的情况下发生,并允许您想要的故事板设置

The < Back button is appearing because you are doing a push segue from the login view controllers to the tab bar controller. A better flow for the app would be to have the tab bar controller be your initial view controller. Then, in its viewDidAppear method, check that the user is logged in. If the user isn't logged in, segue modally WITHOUT animation to your login view controller. This will all happen without the user noticing and will allow the storyboard setup you want

这篇关于在Swift中进行iOS登录/注销实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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