Ajay_Kumar
Ajay_Kumar

Reputation: 1387

How to add image in tableview in iphone

I have to add image in tableview in each. I have 2 list one is for twitter and second is for facebook. I want to show each list with their image icon. here is my code to attach value in table of twitter.

   for (NSDictionary *wallText in sortedarray) {

    NSString *wallNameValue = [wallText objectForKey:@"message"];


    if(![[NSNull null] isEqual:wallNameValue] && [wallNameValue length])
    {


        [tableList addObject:wallNameValue];

    }

}

I want to show twitter image in left of row. How will i add image.

Thanks in advance

Upvotes: 0

Views: 1390

Answers (3)

Ajay Sharma
Ajay Sharma

Reputation: 4517

Just try using in this Way:

cell.imageView.image = [UIImage imagedNamed:[wallText objectForKey:@"message"]];

& plus there is no need to run any loop for this.This is optimize your code.

Just access the array via indexpath.row

NSDictionary *wallText = (NSDictionary *)[[sortedarray objectAtIndex:indexPath.row]valueForKey:message];

Hope you are going to do all these things in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath .

Upvotes: 1

Alex Terente
Alex Terente

Reputation: 12036

In cellForRowAtIndexPath just do

cell.imageView.image = [UIImage imageWithData:[yourImageDataArray objectAtIndex:indexPath.row]];

Upvotes: 0

Tyler
Tyler

Reputation: 28874

In your table view's delegate, in the method that sets up your UITableViewCell's, do something like this:

cell.imageView.image = myImage;
// myImage is a UIImage *.

Every UITableViewCell comes with a UIImageView built in that displays an image for you on the left side of the cell.

Reference: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html

Upvotes: 0

Related Questions