Pass data object to UITableViewCell and use it from inline cell controller

I have a basic method to populate a tableView with a custom cell in Swift

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    let object = array[UInt(indexPath!.row)] as Word
    var cell:DictionaryTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("dictionaryCell") as DictionaryTableViewCell
    cell.originalText.text = object.original
    return cell
}

      

Works great. Now I have a custom cell DictionaryTableViewCell

with custom properties and some IBActions (for different buttons inside this cell).

My question is, how can I provide the data passed to the cell from the tableView and use it from inside my custom cell controller ? For example, I would like to be able to manipulate it for each cell using IBActions.

At the moment my custom cell controller is nothing fancy

class DictionaryTableViewCell: UITableViewCell {

    @IBOutlet weak var originalText: UILabel!
    @IBAction func peak(sender: AnyObject) {

    }
}

      

Is there a custom property that I can use to recover the data passed to it? Or do I need to implement some kind of protocol? If so, how?

+3


source to share





All Articles