didSelectRowAtIndexPath 没有改变 属性 我传递给上一个视图

didSelectRowAtIndexPath is not changing the property I am passing to a previous View

我正在尝试将数据从 tableview 传递到上一个屏幕,即我的 注册 屏幕。具体我发的是一个学校的名字。

发生的事情是,当我通过 segue return 到上一个屏幕时,我正在更改的标签 (schoolTextLabel) 显示 "None Selected",当我想要它时显示学校名称。通过一些错误检查,我发现当我有它时 println(theSchoolName),它正确地选择了我想要显示的名称,只是没有将值传递到另一个屏幕。

请帮忙!
我在互联网上无休止地寻找答案,但终究找不到答案。
谢谢!

TableViewController

var namesArray = [String]()
var locationsArray = [String]()

var theSchoolName = "None Selected"


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "selectedSchool" {
        var completeSignUpVC = segue.destinationViewController as! SignUpViewController
        completeSignUpVC.school = self.theSchoolName
    }
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.theSchoolName = self.namesArray[indexPath.row]
    self.performSegueWithIdentifier("selectedSchool", sender: self.namesArray[indexPath.row])

    println(theSchoolName)
}

SignUpViewController

class SignUpViewController: UIViewController, UITextFieldDelegate {

@IBOutlet var schoolTextLabel: UILabel!
var school = "No School Selected"

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib. 
    self.schoolTextLabel.text = self.school        
    usernameSignupText.delegate = self
    passwordSignupText.delegate = self   
}
}

我找到了答案。我需要找到选定的行索引,然后在 namesArray 中调用该编号。我不确定为什么我以前的代码不起作用,但现在可以了。

var selectedRowIndex = self.schoolTable.indexPathForSelectedRow()
var completeSignUpVC = segue.destinationViewController as! SignUpViewController
completeSignUpVC.school = namesArray[selectedRowIndex!.row]