Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding images to UItableView

Tags:

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

like image 768
jason Avatar asked Feb 15 '11 01:02

jason


People also ask

How do I populate UITableView?

There are two main base ways to populate a tableview. The more popular is through Interface Building, using a prototype cell UI object. The other is strictly through code when you don't need a prototype cell from Interface Builder.

What is the difference between UITableView and UICollectionView?

Tableiw is a simple list, which displays single-dimensional rows of data. It's smooth because of cell reuse and other magic. 2. UICollectionView is the model for displaying multidimensional data .


2 Answers

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.

like image 152
Thomas M Avatar answered Dec 02 '22 02:12

Thomas M


Yes, it is possible. You can take help from cocoawithlove and here. These tutorials will give you an idea how to give images to UITableView. Finally, as asked before on SO, UITableViewCell Set Selected Image.

like image 25
Sudhanshu Avatar answered Dec 02 '22 03:12

Sudhanshu