Since you are using static cells, in which case you only have 3, you could set up IBOutlet in storyboard.
@IBOutlet weak var cell1: UITableViewCell!
@IBOutlet weak var cell2: UITableViewCell!
@IBOutlet weak var cell3: UITableViewCell!
Subsequently, while you are still in storyboard, please set up tags for each cell, by clicking on the Attributes Inspector on the right.
For test, I set up the tags from 0 - 2 (i.e., 0, 1, 2).
I am guessing that you are saving a String value in you main controller, and once clicked, you would like so that the corresponding cell would have a checkmark by getting that value out of NSDefault again.
You could do this in method (Swift-wise: function):
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
Here is what I came up as a quick test:
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
{
NSUserDefaults.standardUserDefaults().setObject("0", forKey: "Sort")
NSUserDefaults.standardUserDefaults().synchronize()
let defaults: NSUserDefaults = NSUserDefaults.standardUserDefaults()
var aString = defaults.valueForKey("Sort") as? String
let cellIndex = aString?.toInt()
if cell1.tag == cellIndex
{
cell1.textLabel!.text = "Hallo, I am cell 1"
cell1.accessoryType = UITableViewCellAccessoryType.Checkmark
}
else if cell2.tag == cellIndex
{
cell2.textLabel!.text = "Hello, I am cell 2"
cell2.accessoryType = UITableViewCellAccessoryType.Checkmark
}
else if cell3.tag == cellIndex
{
cell3.textLabel!.text = "Hello, I am cell 3"
cell3.accessoryType = UITableViewCellAccessoryType.Checkmark
}
}
As test, I set it as 0 and get it back immediately from NSDefault; and the first cell is checked with a checkmark.