Im passing data through 3 VCs, so in the end I want to achieve sending data from the third VC to the first. I send Data from V2 to V3 with a segue and then send it back from V3 to V2 by delegate. Im then trying to send it from V2 to V1 through a segue but I cant seem to collect the data (sent back from V3) in V2 to then send to V1. The data from V3 doesn't show up in V1, but the code still runs.
Can anyone help?
heres my code from V2 and V3:
V2:
import UIKit
class SecondViewController: UIViewController, thirdDelegate {
var GetBack: String?
var SendForward = [String]()
var Datacollect = [String]()
var Collect = [String]()
let ct = "Conner@2"
let new = "All@2"
@IBOutlet var Hinput: UITextField!
@IBOutlet var Ninput: UITextField!
@IBAction func MAP(_ sender: Any) {
if Hinput.text != ""{
performSegue(withIdentifier: "SegueSearch", sender: self)}
}
@IBAction func Info(_ sender: Any) {
performSegue(withIdentifier: "SegueInfo", sender: self)
}
func DataToPass(ArrayName: [String]) { //function from delegate
Datacollect = ArrayName
print(ArrayName)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?){
if segue.identifier == "SegueSearch"{
let thirdController = segue.destination as! ThirdViewController
SendForward.append(Hinput.text!)
SendForward.append(ct)
thirdController.height = SendForward
thirdController.delegate = self
} else if segue.identifier == "SegueInfo" {
let firstController = segue.destination as! ViewController
if Datacollect.count != 0{
Collect.append(Datacollect[1])
Collect.append(Datacollect[0])}
Collect.append(Ninput.text!)
Collect.append(new)
firstController.AllData = Collect
}
}
override func viewDidLoad() {
super.viewDidLoad()
print("check",Datacollect)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Is this the part that isn't working?
func DataToPass(ArrayName: [String]) {
Datacollect = ArrayName
print(ArrayName)
}
V3:
import UIKit
protocol thirdDelegate{
func DataToPass (ArrayName: [String])
}
class ThirdViewController: UIViewController {
var height = [String]()
var SendBack = [String]()
let ko = "Keith@3"
var delegate: thirdDelegate! = nil
@IBOutlet var Houtput: UILabel!
@IBAction func Home(_ sender: Any) {
let StrH = String(height[0])
SendBack.append(ko)
SendBack.append(StrH!)
delegate.DataToPass(ArrayName: SendBack)
}
override func viewDidLoad() {
Houtput.text = height[0]
super.viewDidLoad()
print(height)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}