简体   繁体   中英

Function Not Being Called Through Segue in Swift 4.0

I've started to learn Swift 4 and iOS app development.

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. 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.

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. 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.

import UIKit import Parse

class 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保存灰色文件,然后您的更改将反映到最新运行的应用程序中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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