I have a TableView and in it I have a cell that I need to change the background color of. I've tried searching for an answer to change the background color of the cell but the problem is that every answer I find has to do with an override tableview function, which will not work because I do not have a tableviewcontroller, rather it is a normal view controller with a UITableView embedded.
How can I simply change the background color of the cell?
First give your table view cell an Identifier via the storyboard like this:
Then additionally to vadian's answer access your cell in the
tableView(_:cellForRowAt:)
DataSource method like this and update the color, in the example I put the method in an extension:Also don't forget to add the
tableView(_:numberOfRowsInSection:)
method to conform the UITableViewDataSource protocolLike rMickeyD mentioned in the comments, don't forget to set your table view as
dataSource
anddelegate
withCtrl + Drag
from the table view to the view controller like this:It doesn't matter if it's an implicit or explicit table view.
In
cellForRowAtIndexPath
set the propertybackgroundColor
of the cell: