我正在显示一个带有 UITableView 控件的 UIView。我通过调用 PerformSegueWithIdentifier 使用 Show Segue 显示此视图。在调用 segue 的模块中,我添加了一个要在展开时使用的函数,以便在从 segue 返回时从视图中检索一些数据。现在,我有一个“完成”按钮,它连接到调用者的函数,这样我就可以在 segue 展开时检索数据。我不想在点击“完成”按钮时执行所有这些操作,而是希望在 UITableView 中选择一个项目时执行此操作。
在 tableView(,willSelectRowAtIndexPath) 中,我尝试调用 popViewControllerAnimated。第二个 UIView 确实关闭并将我带回调用 UIView,但未调用展开函数。
我知道如何使用 Exit 从完成按钮设置展开,但我不知道在点击 UITableView 中的一行时如何执行此操作。
这是我用来执行 segue 的代码:
@IBAction func fromButtonTap(sender: AnyObject) {
currentButton = sender.tag
self.performSegueWithIdentifier("UnitsSegue", sender: self)
}
下面是当 segue 展开时执行的代码:
@IBAction func returnFromUnitSelection(segue: UIStoryboardSegue) {
var buttonToSet: UIButton!
var unitsToSet: UnitData!
fromLabel.text = "0"
toLabel.text = "0"
if let unitsSelectionViewController = segue.sourceViewController as? UnitSelectionController {
if currentButton == 0 {
fromUnitData = unitsSelectionViewController.selectedUnit
buttonToSet = fromButton
}
else {
toUnitData = unitsSelectionViewController.selectedUnit
buttonToSet = toButton
}
setButtonText(buttonToSet, firstLine: unitsSelectionViewController.selectedUnit.unitCode, secondLine: unitsSelectionViewController.selectedUnit.unitName, firstLineFontSize: 15, secondLineFontSize: 11)
}
}
这是我用来关闭第二个 UIView 的代码:
func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
selectedUnit = temperatures[indexPath.row]
self.navigationController?.popViewControllerAnimated(true)
return indexPath
}
当我点击“完成”时,展开代码确实会执行。但是当我在表中选择一个项目时什么也没有发生。