0

I am looking to pass data from a UITableView to a UIViewController through a UINavigationController. Here is my storyboard:

Main storyboard

EDIT1: My delegate doesn't seem to be working

My registration class:

class RegisterViewController: UIViewController, UniSnapshotProtocol {

    @IBOutlet var registerName: UITextField!
    @IBOutlet var registerEmail: UITextField!
    @IBOutlet var registerPassword: UITextField!
    @IBOutlet var registerConfirmPassword: UITextField!

    //conforming to protocol we will need the same function listed in the protocol of the other other page.
    var univSnapshotFromUnivTableViewController:FIRDataSnapshot!

    func sendBackUnivSnapshot(univSnapshot:FIRDataSnapshot){
        print("Print if delegate works correctly")
        self.univSnapshotFromUnivTableViewController = univSnapshot
    }
override func viewDidLoad() {
        super.viewDidLoad()
        //lets see if we get information back from the UITableViewController

    }
override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)

        if let univSnapshot = univSnapshotFromUnivTableViewController{
            print("Something came through")
            print(univSnapshot)
        }else{
            print("Nothing came through from delegate\n")
        }
    }
}

//This is how to go to my `tableViewController` by clicking on one of the `UITextField`:

    @IBAction func selectUsers(_ sender: UITextField) {
        moveToUnivTableView()
    }

    func moveToUnivTableView() {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let profileView = storyboard.instantiateViewController(withIdentifier:"univNavigationController") as! UINavigationController
        profileView.delegate? = self as! UINavigationControllerDelegate
        self.present(profileView, animated:true, completion:nil)
    }

My 'UITableViewController' class:

//passing data back to the registration page
protocol UniSnapshotProtocol{
    func sendBackUnivSnapshot(univSnapshot:FIRDataSnapshot)
}
class UnivTableViewController: UITableViewController,UISearchResultsUpdating {
    var delegate:UniSnapshotProtocol!

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        //send the information back as delegate
        self.univDatabase.removeAllObservers()//need to remove all observers else on dismiss it overwrites the array so nothing to send back
        cellRow = indexPath.row
//                print(self.snapshotArray[indexPath.row])
        self.dismiss(animated: false, completion: nil)//dismisses the focused cells without animation
        self.navigationController?.dismiss(animated: true, completion: {self.fireAuth.currentUser?.delete(completion: nil)})
    }
//from once the view is dismissed from clicking a cell the delegate should be able to run the function in UIView Controller.
func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
        if self.isBeingDismissed {
            self.delegate?.sendBackUnivSnapshot(univSnapshot: self.snapshotArray[cellRow] )
        }
    }
}

What is the solution to come back to the registration page with some data from the UITableViewController in Swift?

0 Answers0