简体   繁体   English

在 Swift 4.0 中没有通过 Segue 调用函数

[英]Function Not Being Called Through Segue in Swift 4.0

I've started to learn Swift 4 and iOS app development.我已经开始学习 Swift 4 和 iOS 应用程序开发。

I've set up a basic app that allows users to sign up and add themselves to a user table or log in and display the users that are already registered.我已经设置了一个基本的应用程序,它允许用户注册并将自己添加到用户表或登录并显示已经注册的用户。 I've created a bar button item (logout) in my main storyboard and have connected that button to the main user screen with a segue.我在我的主故事板中创建了一个栏按钮项(注销),并使用 segue 将该按钮连接到主用户屏幕。 I've also created a user table view controller with the function to logout the user.我还创建了一个具有注销用户功能的用户表视图控制器。 Here are the images of if the code, main storyboards, and segue and button definitions.以下是 if 代码、主故事板以及转场和按钮定义的图像。

The issue is that when I press the logout button in the app, the actual logout function is never called.问题是当我按下应用程序中的注销按钮时,从未调用实际的注销功能。 I believe it works because it flashes the main user signup screen for a second (as per the segue), but that code is never executed.我相信它有效,因为它会在主用户注册屏幕上闪烁一秒钟(根据 segue),但该代码从未执行过。 It just goes back to the main user table view.它只是回到主用户表视图。 I added print statements (for the console) and breakpoints in the code but it never gets that far.我在代码中添加了打印语句(用于控制台)和断点,但它从来没有那么远。 Here's the code below.这是下面的代码。 It's in the UserTableViewController.swift file.它在 UserTableViewController.swift 文件中。

import UIKit import Parse导入 UIKit 导入解析

class UserTableViewController: UITableViewController {类 UserTableViewController: UITableViewController {

//function to control what happens when the user presses the logout button


@IBAction func logoutUser(_ sender: Any) {

    // log the user out; make sure you import Parse into the view controller so you can access the PFUser functions
    print ("getting ready to logout user")

    PFUser.logOut()

    print ("logged out user from parse")

    // perform the segue to the main login screen; don't need self. before the performSegue because we want the action to happen in the main view controller

    performSegue(withIdentifier: "logoutSegue", sender: self)

    print("You should see the main screen now")

}

Thanks in advance for your help.在此先感谢您的帮助。 Sorry for adding in the pictures earlier.很抱歉之前添加了图片。

Mike麦克风

您的 main.storyboard 图标是灰色的,因为您需要保存该文件。

您需要按Command+S保存灰色文件,然后您的更改将反映到最新运行的应用程序中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM