I am trying to pass a full array between view controllers but cannot figure out the missing piece.
In view controller one I have:
protocol ExclusionsViewViewControllerDelegate{
func ExcUpperDidFinish(controller:ExclusionsView)
func ExcLowerDidFinish(controller:ExclusionsView)
}
class ExclusionsView: UIViewController, UITableViewDataSource, UITableViewDelegate {
var delegate:ExclusionsViewViewControllerDelegate? = nil
var ExcLowerArray:[Int]=[]
var ExcUpperArray:[Int]=[]
@IBOutlet var ExcLowerText: UITextField!
@IBOutlet var ExcUpperText: UITextField!
@IBOutlet var ExcFreqTable: UITableView!
@IBAction func BackButton(sender: AnyObject) {
if (delegate != nil){
delegate!.ExcUpperDidFinish(self, Array: ExcUpperArray)
delegate!.ExcLowerDidFinish(self, Array: ExcLowerArray)
}
dismissViewControllerAnimated(true,completion:nil)
}
In View controller two I have:
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, PreferencesViewControllerDelegate, ExclusionsViewViewControllerDelegate {
var ExcUpperFreqArray:[Int]=[]
var ExcLowerFreqArray:[Int]=[]
override func viewDidLoad() {
super.viewDidLoad()
}
func ExcLowerDidFinish(controller: ExclusionsView, Array:[Int]) {
ExcLowerFreqArray = Array
controller.navigationController?.popViewControllerAnimated(true)
}
func ExcUpperDidFinish(controller: ExclusionsView, Array:[Int]) {
ExcUpperFreqArray = Array
controller.navigationController?.popViewControllerAnimated(true)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "pushExclusions"{
let zc = segue.destinationViewController as ExclusionsView
zc.ExcLowerArray = ExcLowerFreqArray
zc.ExcUpperArray = ExcUpperFreqArray
}
}
I cannot figure out how to correctly reference the array. I am trying to create the array ExcLowerArray in view controller one, and when I change view it will copy all data to the array ExcLowerFreqArray in the second view controller, so that I can reference it in that view controller. At the moment though I get an error on these two lines: delegate!.ExcLowerDidFinish(self, Array: ExcLowerArray) func ExcLowerDidFinish(controller: ExclusionsView, Array:[Int]) {