145478272452
145478272452

Reputation: 91

Adding Image to Table Cell (iOS)

I am trying to do something similar to twitter or Facebook.

Upvotes: 9

Views: 20203

Answers (3)

Esqarrouth
Esqarrouth

Reputation: 39201

Swift version:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

  let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell

  cell.textLabel.text = "I'm a UITableViewCell!";
  cell.textLabel.textColor = UIColor.whiteColor()
  cell.imageView.image = UIImage(named: "MyReallyCoolImage.png")

  return cell;
}

Upvotes: 0

Erick Smith
Erick Smith

Reputation: 930

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
{    
   static NSString* CellIdentifier = @"Cell";

   UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil)
      cell = [[[UITableViewCell alloc] UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

   cell.textLabel.text = @"I'm a UITableViewCell!";
   cell.imageView.image = [UIImage imageNamed:@"MyReallyCoolImage.png"];

   return cell;
}

Credit to Thomas Moore

adding images to UItableView

Upvotes: 18

W Dyson
W Dyson

Reputation: 4634

Well, to add an image to a table cell, you would add a UIImage to the image property of a subtitle UITableViewCell or your own custom Cell. I would read the doc on Customizing UITableViewCells at developer.apple.com.

Upvotes: 1

Related Questions