Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is it possible to add images to a table view? To the left side? And if so, what size should it be?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
439 views
Welcome To Ask or Share your Answers For Others

1 Answer

A custom UITableViewCell is not required to simply add an image to the left side of the cell. Simply configure the imageView property of the UITableView cell in your tableView:cellForRowAtIndexPath: delegate method like so:

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

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

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

   return cell;
}

Unless you provide a tableView:heightForRowAtIndexPath: method in your UITableViewDelegate, the default height of a UITableViewCell is 44 points, which is 44 pixels on a non-retina display and 88 pixels on a retina display.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...