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 lengt开发者_Python百科h])
{
[tableList addObject:wallNameValue];
}
}
I want to show twitter image in left of row. How will i add image.
Thanks in advance
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 .
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
In cellForRowAtIndexPath
just do
cell.imageView.image = [UIImage imageWithData:[yourImageDataArray objectAtIndex:indexPath.row]];
精彩评论