Swift 通过UINavigationController将数据从UITableView传递到UIViewController

Swift 通过UINavigationController将数据从UITableView传递到UIViewController,swift,uitableview,uiviewcontroller,swift3,uinavigationcontroller,Swift,Uitableview,Uiviewcontroller,Swift3,Uinavigationcontroller,我希望通过UINavigationController将数据从UITableView传递到UIViewController。这是我的故事板: EDIT1:我的代表似乎没有工作 我的注册班: class RegisterViewController: UIViewController, UniSnapshotProtocol { @IBOutlet var registerName: UITextField! @IBOutlet var registerEmail: UITex

我希望通过
UINavigationController
将数据从
UITableView
传递到
UIViewController
。这是我的故事板:

EDIT1:我的代表似乎没有工作

我的注册班:

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)
    }
我的“UITableViewController”类:

//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] )
        }
    }
}

使用Swift中的
UITableViewController
中的一些数据返回注册页面的解决方案是什么?

在视图控制器中创建一个类变量。并在显示视图控制器之前将值传递给它。是否向我们显示您的代理代码。您可以使用多种方法执行此操作,例如,
delegate
userdefaults
coredata
nsnotifications
。试一试these@NiravD我添加了我的委托代码。