2014-02-10 2 views
-1
-(void)viewDidLoad { 
    [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.navigationItem.title = @"New Arrivals"; 

    [super viewDidLoad]; idsArray=[[NSMutableArray alloc]init]; namesArray=[[NSMutableArray alloc]init]; imagesArray=[[NSMutableArray alloc]init]; 

    // create the URL we'd like to query 

    NSURL *myURL = [[NSURL alloc]initWithString:@"http://www.bikrionline.com/nwarvl-json.php"]; 

    // we'll receive raw data so we'll create an NSData Object with it NSData *myData = [[NSData alloc]initWithContentsOfURL:myURL]; 

    // now we'll parse our data using NSJSONSerialization if ([myData length]>0) { id myJSON = [NSJSONSerialization JSONObjectWithData:myData options:NSJSONReadingMutableContainers error:nil]; NSArray *jsonArray = (NSArray *)myJSON; for (int i=0 ; i<[jsonArray count] ; i++) { NSMutableString *urlString = [[NSMutableString alloc]initWithString:@"http://www.bikrionline.com/products/zmphotos/"]; NSString * name = [[[jsonArray objectAtIndex:i]objectForKey:@"prodname"]retain]; [namesArray addObject:name]; [idsArray addObject:[[jsonArray objectAtIndex:i]objectForKey:@"prodid"]]; [urlString appendString:[[jsonArray objectAtIndex:i]objectForKey:@"imageurl"]]; UIImage *imageObj = [self getImageFromUrl:urlString]; urlString = nil; [imagesArray addObject:imageObj]; } } 

} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    CustomCellView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     NSArray *arrNib = [[NSBundle mainBundle] loadNibNamed:@"CustomCellView" owner:self options:nil]; 
     cell = [arrNib objectAtIndex:0]; 
    } 
    cell.imgName.text = [namesArray objectAtIndex:indexPath.row]; 
    cell.custImageView.image=[imagesArray objectAtIndex:indexPath.row]; 

    return cell; 
} 

ответ

1

Вы можете использовать некоторые Lib, такие как SDWebImage или Afnetworking. Libs поддерживает ленивое изображение загрузки и автоматически кэширует это изображение. Все, что вам нужно сделать:

[cell.imageView setImageWithURL:[NSURL URLWithString:@"url of image"] 
       placeholderImage:nil]; 
Смежные вопросы