【发布时间】:2014-11-02 16:24:57
【问题描述】:
我正在发送 json 并将值存储在 Collection 视图中,数组在 didSelectItemAtIndexPath 处显示为空,请帮助我..
NSDictionary * jsonResult = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];
albumImageArr = [NSMutableArray array];
[albumImageArr addObjectsFromArray:[jsonResult objectForKey:@"photoList"]];
NSLog(@"Array %@",albumImageArr);
for (NSDictionary *dic in albumImageArr)
{
str1=[dic objectForKey:@"photoURL"];
[arr addObject:str1];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView1 cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
CustomCell *cell = (CustomCell *)[collectionView1 dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
NSString *path = [[albumImageArr objectAtIndex:indexPath.row] objectForKey:@"photoURL"];
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [[UIImage alloc] initWithData:data];
cell.imageView.image = image;
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView1 didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PhotoDescriptionViewController *albumsController = (PhotoDescriptionViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"DescriptionView"];
NSString *senderImg=[arr objectAtIndex:indexPath.item];
albumsController.receivedImage=senderImg;
[self.navigationController pushViewController:albumsController animated:YES];
}
【问题讨论】:
-
请说明您进行了哪些调试以尝试解决此问题。
-
我在 cellForRowAtIndexPath 中显示图像数据。我想用 didSelectItemAtIndexPath 在detailedViewController 中显示图像数据。
-
那么,你在 didSelectItemAtIndexPath 中访问相同的数据结构吗?不要指望从单元格中获取数据,从你的数据结构中获取。
标签: ios iphone json ios7 uicollectionview