In swift I have two view controllers. One is a tableView and displays data from an array. On a function call the other view controller calls the tableView and delivers arguments with new data for the table view. Even when I update the array buckets where the data is taken from the TableView doesn't update. How do I get the program to reload its data?
TABLE VIEW
import Foundation
import UIKit
class BucketTableViewController: UITableViewController {
var buckets = ["A", "B", "C"]
override func viewDidLoad() {
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return buckets.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
cell.textLabel?.text = buckets[indexPath.row]
return cell
}
func updateBuckets(newBucket: NSArray) {
buckets = newBucket as! [String]
self.tableView?.reloadData()
}
}
I can verify that updateBuckets is called from the other view controller.
OTHER VIEW CONTROLLER
var bigArray = ["M", "A", "R", "C"]
override func viewDidLoad() {
super.viewDidLoad()
let buckets = BucketTableViewController()
buckets.updateBuckets(bigArray)
}