I have the following code: (Note: newsImageURL
is an NSArray
)
NSString *imagesURL = @\"http://aud.edu/images/newsimage01.png,http:/
You can load data this way:
NSData *data = [NSData dataWithContentsOfURL: [NSURL URLWithString: [newsImageURL objectAtIndex:indexPath.row]]];
And you can instantiate the array of URLs this way too:
NSArray *newsImageURL = [imagesURL componentsSeparatedByString:@","];
However, if someone scrolls around on the table a great deal, you may end up loading the images many times over as the cells are recycled.
You should use an existing framework which supports caching, default place holders and lazy loading of images.
https://github.com/rs/SDWebImage is a good and simple framework
#import "UIImageView+WebCache.h"
...
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier] autorelease];
}
// Here we use the new provided setImageWithURL: method to load the web image
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://aud.edu/images/newsimage01.png,http://aud.edu/images/newsimage04.png"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
cell.textLabel.text = @"My Text";
return cell;
}
You Can Easily load all the images with the Help of Following code ,Details Array is a Main Array
Details Array :- {
"item_code" = 709;
"item_desc" = Qweqweqwe;
"item_name" = AQA;
"item_photo" = "http://toshaya.com/webapp/snap&sell/api/img_items/709.png";
"item_price" = "0.00";
"item_till" = "20-25";
"item_type" = Orange;
latitude = "";
longitude = "";
}
With the Help of Following Code Retrieve The Photo-URL into String
NSString * result = [[DetailArray objectAtIndex:indexPath.row]objectForKey:@"item_photo"]; //componentsJoinedByString:@""];
NSLog(@"%@",result);
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:result]];
cell.icon.image = [UIImage imageWithData:imageData];
Maybe you can have a try https://github.com/SpringOx/ALImageView.git.It is much simpler than SDWebImage.You only need two source files(ALImageView.h/ALImageView.m).You can reuse the image view to reload different urls in a tableview cell.