I'm registering a custom cell from a Nib in the TableViewController
tableView.registerNib(UINib(nibName: "CustomCell", bundle: nil), forCellReuseIdentifier: "Cell")
but my CustomCell has IBAction methods that need access to the tableView itself and the fetchedResultsController. How do I pass those parameters in a clean way to the CustomCell?
Setting those things in:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) {
return tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
}
doesn't seem to be the clean way to me..?
The cell really shouldn't know anything about the table view or the fetchedResultsController. One way to do this is to add your actions in cellForRowAtIndexPath, and make the controller the target.
Another option is to have the action methods in the custom cell class, and have them call delegate protocol methods that you create in the cell class. Have the controller set itself as the delegate in cellForRowAtIndexPath.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With