I am storing a list of URLs in a mySQL db table and I have been able to successfully retrieve the URLS via JSON. However, now that i have the JSON I am not sure how to display the images in a image gallery type view in my iPhone app.
What i plan on having is a huge list of URL's to image in the database and i want to display x amount at a time and then once the user scrolls to the end I want to display x amount more. Like pinterest.
Any hints?
#import "mySQLAppViewController.h"
@interface mySQLAppViewController (){
}
- (IBAction)loadJSON:(id)sender;
@end
@implementation mySQLAppViewController
- (IBAction)loadJSON:(id)sender {
NSString *dataUrl = [NSString stringWithFormat:@"http://MYDOMAIN.com/results.php"];
NSURL *url = [NSURL URLWithString:dataUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
for (int i =0 ; i < [JSON count]; i++) {
//NSString *image_url = JSON[i][@"image_url"];
//NSLog(@"%@", image_url);
//^^THIS SUCESSFULLY LOGS THE URL LINKS (I.E. HTTP://MYDOMAIN.COM/CAR.JPG)
NSURL *imageURL = [NSURL URLWithString:JSON[i][@"image_url"]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
}
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Weather"
message:[NSString stringWithFormat:@"%@",error]
delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil];
[av show];
}];
[operation start];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end