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_Uiviewcontroller - Fatal编程技术网

Ios 搜索过滤器

Ios 搜索过滤器,ios,swift,uiviewcontroller,Ios,Swift,Uiviewcontroller,我想为搜索做一个过滤器(在一个单独的屏幕上),我想如何为我的第二个viewcontroller传输数据。 有没有办法使用像C++那样的指针?当数组中的所有更改(在第二个视图中)在第一个视图中更改时,也就是说,实际上我不需要复制数据,因为我使用了指针。如果我不能使用它,在第一次查看时更改后如何传输我的数组?不要使用指针,通过将数组传输。使用委托将数据传递回上一个类 从头等舱开始 class FirstClass: UIViewController, SecondClassDelegate { @

我想为搜索做一个过滤器(在一个单独的屏幕上),我想如何为我的第二个viewcontroller传输数据。
有没有办法使用像C++那样的指针?当数组中的所有更改(在第二个视图中)在第一个视图中更改时,也就是说,实际上我不需要复制数据,因为我使用了指针。如果我不能使用它,在第一次查看时更改后如何传输我的数组?

不要使用指针,通过将数组传输。

使用
委托
将数据传递回上一个类

从头等舱开始

class FirstClass: UIViewController, SecondClassDelegate {

@IBAction func goToSecondClass(_ sender: Any) {
    performSegue(withIdentifier: "SecondClassId", sender: nil)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let destination = segue.destination as? SecondClass {
        destination.delegate = self
    }
}

func finishPassing(stringPassed: String) {
   print(stringPassed)
}

}
在二等舱

protocol SecondClassDelegate {
    func finishPassing(string: String)
}

class SecondClass: UIViewController {
@IBAction func btnPassDataPressed(_ sender: Any) {
    var delegate: SecondClassDelegate?
    delegate?.finishPassing(string: "Data passed from Second Class")
  }
}
这里有三条路:

如果必须将数据传递给上一个控制器,则使用自定义委派

若必须将数据传递给下一个控制器,那个么只需将数据分配给下一个视图控制器变量即可

您可以通过将数据保存在Userdafults中来获取数据。

请参阅可能的重复数据