如何显示我的urljson数据到collections视图

我已经从授权标题的一个url获取数据,我转换为json

在我的json我只有PDF文件。 但我不想显示PDF文件。 我想显示文件名(例如: document1.pdfdocument2.pdf ),而且我有3个部分 – 每个部分包含10个文件。 所以我需要显示文件的名称。

我看到一些只使用图像而不是文档文件的教程。 那么如何将我的文档名称单独显示到集合视图。

还有一个问题。 我是否需要解码来显示我的数据或不想这样做。 帮助我。提前感谢!

  NSMutableArry *arrayPDFName = [[NSMutableArray alloc]init]; NSDictionary *jsonResults = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil]; NSDictionary *dictOriginal = [jsonResultsvalueForKey:@"original"]; NSArray *arrayFiles = [[dictOriginal valueForKey:@"files"] copy]; NSLog(@"The arrayFiles are - %@",arrayFiles); for(int i=0;i<[arrayFiles count];i++) { NSString *strCreatedTime = [NSString stringWithFormat:@"%@",[[arrayFiles objectAtIndex:i] valueForKey:@"created_time"]]; NSString *strLastModifiedTime = [NSString stringWithFormat:@"%@",[[arrayFiles objectAtIndex:i] valueForKey:@"last_modified_time"]]; NSString *strID = [NSString stringWithFormat:@"%@",[[arrayFiles objectAtIndex:i] valueForKey:@"id"]]; NSString *strName = [NSString stringWithFormat:@"%@",[[arrayFiles objectAtIndex:i] valueForKey:@"name"]]; NSLog(@"The created_time is - %@",strCreatedTime); NSLog(@"The last_modified_time is - %@",strLastModifiedTime); NSLog(@"The is is - %@",strID); NSLog(@"The name is - %@",strName); [arrayPDFName addObject:strName]; } } 

在collectionview中你需要使用上面的arrayPDFName(在集合视图中委托方法)

在CollectionView中显示数据

 - (void)viewDidLoad { [super viewDidLoad]; [self getResponse]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; //Register the custom cell for collection view UINib *cellNib = [UINib nibWithNibName:@"CustomCell" bundle:nil]; [collectionViewHorizontalVertical registerNib:cellNib forCellWithReuseIdentifier:@"cvCell"]; } //Collection View Delegates method -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return arrayPDFName.count; } -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"cvCell"; CustomCell *cell = (CustomCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; //data for text cell.textField.text = [arrayPDFName objectAtIndex:indexPath.row]; //OR Image cell.imgViewCollection.image = [UIImage imageNamed:[arrayPDFName objectAtIndex:indexPath.row]]; return cell; } // If you want to set the cell height - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(200, 200); //Please give your required size }