Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 以编程方式展开序列_Ios_Swift - Fatal编程技术网

Ios 以编程方式展开序列

Ios 以编程方式展开序列,ios,swift,Ios,Swift,我正在显示带有UITableView控件的UIView。我通过调用performsguewithidentifier以显示序列来显示此视图。在调用segue的模块中,我添加了一个我希望在展开时使用的函数,以便在从segue返回时从视图中检索一些数据。现在,我有一个Done按钮,它连接到调用者的函数上,这样我就可以在segue展开时从中检索数据。我希望在UITableView中选择一个项目时执行此操作,而不是在点击“完成”按钮时执行所有操作 在tableView(,willSelectRowati

我正在显示带有UITableView控件的UIView。我通过调用performsguewithidentifier以显示序列来显示此视图。在调用segue的模块中,我添加了一个我希望在展开时使用的函数,以便在从segue返回时从视图中检索一些数据。现在,我有一个Done按钮,它连接到调用者的函数上,这样我就可以在segue展开时从中检索数据。我希望在UITableView中选择一个项目时执行此操作,而不是在点击“完成”按钮时执行所有操作

在tableView(,willSelectRowatinexPath)中,我尝试调用popViewControllerAnimated。第二个UIView确实关闭并将我带回调用UIView,但未调用unwind函数

我知道如何使用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
}

当我点击“完成”时,会执行展开代码。但当我在表格中选择一个项目时,什么也不会发生。

您可以为整个视图控制器创建展开序列。要执行此操作,请将segue从视图控制器objet拖动到退出对象

创建segue后,它将列在文档大纲中

选择它并在属性检查器中为其指定一个标识符。然后,在您的代码中,当tableview选择一个单元格时,像任何其他正常的序列一样执行此序列

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let title = tableView.cellForRowAtIndexPath(indexPath)?.textLabel?.text

    performSegueWithIdentifier("backToViewController1", sender: title)
}
然后重写
prepareforsgue
方法将数据传递给第一视图控制器

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if let identifier = segue.identifier where identifier == "backToViewController1",
       let destination = segue.destinationViewController as? ViewController,
           selectedTitle = sender as? String {
        destination.selectedCountryTitle = selectedTitle
    }
}

已添加代码。谢谢。这起作用了。我不必重写prepareForSegue。当我从视图中拖动以退出时,将显示一个带有“展开”功能的弹出窗口。我真的不知道它为什么或者如何知道显示那个特定的功能。我选择了它,并将PerformsgueWithIdentifier放在我的tableView函数中,它工作了。如果需要将数据传递给第一个视图控制器,则需要重写PrepareForegue为什么我不能将segue从视图控制器objet拖到exit对象?您必须右键单击并从视图控制器拖到exit