James James - 2 months ago 5
Objective-C Question

Programatically Add Image to TableView Cell

I have a

UITableView
that gets information from a server and publishes the data into a table view. Inside of each cell is the information from the server.

For the purpose of this example, let's say the information we get from the server are numbers: 1, 2, 3, 4.

What I want to do is add an image (programatically because there are if statements involved, etc) to the left side of the cell, and the text (1, 2, etc) right next to it.

Basically, I want each cell to look like this:

_____________________________________
| (IMAGE) (TEXT) | --CELL 0
--------------------------------------
_____________________________________
| (IMAGE) 2 | --CELL 1
--------------------------------------


Please excuse my crude illustration. :)

Answer

here you go:

cell.imageView.image = [UIImage imageNamed:@"image.png"];
Comments