James James - 1 year ago 87
Objective-C Question

Programatically Add Image to TableView Cell

I have a

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 Source

here you go:

cell.imageView.image = [UIImage imageNamed:@"image.png"];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download