2014-05-08 67 views
2

如何在UICollectionview中顯示視頻和圖像。
我給定的URL對這一觀點:需要在uicollectionview中顯示視頻和圖像

http://exarcplus.com/check.png

的圖像和視頻從服務器使用JSON獲取。對於圖像

代碼從服務器上獲取:

NSDictionary *appsdict = [array_all objectAtIndex:indexPath.item]; 
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[appsdict objectForKey:@"url"]]]; 
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { 
     [cell.image_gallery setImage:[UIImage imageWithData:data]]; 
    }]; 
////////but don't know how to fetch videos from server 

回答

0

您需要AsyncImageView類導入到你的項目,並採取圖像視圖,並與給定的標籤集合視圖電池標籤如下解釋:

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
    return [your array count]; 
} 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *identifier = @"MyGridViewCell"; 

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 


    AsyncImageView *imageView = (AsyncImageView *)[cell viewWithTag:1]; 

    [[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:imageView]; 
    imageView.imageURL =[NSURL URLWithString:[your array objectAtIndex:indexPath.row][@"product_image"]]; 

    UILabel *titleLabel = (UILabel *)[cell viewWithTag:2]; 

    NSString *nameText = [NSString stringWithFormat:@"%d. %@",indexPath.row+1,[arrayforlistt objectAtIndex:indexPath.row][@"product_name"]]; 
    titleLabel.text= nameText; 
    return cell; 

} 

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 
{ 
    return 1; 
} 

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // enter your code here if you want to perform any action on the did select of the project 
} 
+0

你能告訴我如何從服務器的細節獲取視頻.. – sures

+0

視頻的格式也是相同的圖像讀取視頻網址的標籤,並存儲在陣列中的網址,並顯示在集合視圖 –

相關問題