RSS

Add chevrons and images from URL to Table View

15 Feb

The following code adds images from URLs and chevrons to Table View like on the image below:

table view with images

- (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];
    }
    
    // Configure the cell...
    cell.textLabel.text = [self.propertyList objectAtIndex: [indexPath row]];
	
    // show chevron on the right
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	
    NSString *path = @"http://assets.survivalinternational.org/static/lib/img/content/video_icon.png";
    NSURL *url = [NSURL URLWithString:path];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *icon = [[UIImage alloc] initWithData:data cache:NO];
    cell.image = icon;
    
    return cell;
}
Advertisements
 
Leave a comment

Posted by on February 15, 2011 in Apple

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: