swift: send value back to UITableViewController from dynamic cell with UIDatePicker

300 Views Asked by At

I've got a dynamic table with a cell for a UIDatePicker. There's a function in the UITableViewCell class that updates a variable when the picker changes. I'm just having trouble getting that value back to the UITableViewController class. I can print the correct variable while spinning the picker, but when I go to reloadRowsAtIndexPaths for the tableView I need the value available.

Since there's no segue, I can't get a protocol/delegate to work. I imagine a global variable might also work, but that's cheating. Any suggestions?

1

There are 1 best solutions below

0
On BEST ANSWER

You can use NSUserDefaults for storing values globally which can access anywhere into your project. you can set values this way for your picker.

NSUserDefaults.standardUserDefaults().setObject("YouValueForm", forKey: "YourKey")

After that you can access this value anywhere in your project this way:

let yourVar = NSUserDefaults.standardUserDefaults().objectForKey("YourKey") as! String

You can modify this as per your need. and once you got your values you can do reloadRowsAtIndexPaths.

Hope this will help.