在uicollectionview中无法显示uimages集

时间:2015-02-23 18:39:52

标签: ios objective-c uicollectionview

  @implementation StudyViewController


      - (void)viewDidLoad {
[super viewDidLoad];
//[super viewWillAppear:animated];

... 基本上我通过afnetworking接收响应对象。 然后将数据存储在名为arData

的全局定义的可移动数组中
                ............
                ...........

            [manager POST:studysearchUrl parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {

    [MBProgressHUD hideHUDForView:self.view animated:YES];

    NSLog(@"%@",responseObject);

    [Global sharedGlobal].arrData = responseObject;

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    NSLog(@"Error: %@", error);
}];

}

     #pragma collection view methods


-      (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView {

return 1;
    }

     -(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

   {
   return [[[Global sharedGlobal]arrData] count];


  }
 -(UICollectionView *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {



    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"StudyCell" forIndexPath:indexPath];

然后,在创建图像路径时,将nsmutable对象索引存储为要访问的字典。 我需要从这个nsmutable数组中提取3组数据(firstUID,second,third),这些数据将被传递给NSURL以构建图像url路径,如下所示。 其余参数(hyperText,UrlKey,portNumber,seperator)通过nsdictionary传递(此处未显示)。

           UIImageView *img = (UIImageView *)[cell viewWithTag:1000];
           NSDictionary *dictionary = [Global sharedGlobal].arrData[indexPath.row];


          img.imageURL = [NSURL URLWithString:[NSString    stringWithFormat:@"%@%@%@%@?parametersintheWebServer&firstID=%@&secondID=%@&thirdID=%@",hyperText, UrlKey, portNumber, seperator, [Global sharedGlobal].arrData[indexPath.row] [@"firstUID"],[Global sharedGlobal].arrData[indexPath.row][@"secondUID"],[Global sharedGlobal].arrData[indexPath.row][@"thirdUID"]]];









      return cell;


    }


     - (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

     }
     @end

1-我似乎无法在控制台内部获取NSLOG输出

           -(UICollectionView *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

2-即使我知道从Web服务收到的参数是正确的,我也无法显示任何图像(&我可以在viewdidload时对它们进行NSLOG而没有任何问题。

任何帮助将不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:1)

您首先应该看到对numberOfItemsInSection的来电。如果你可以在那里设置一个断点(或NSLog)并且[[[Global sharedGlobal]arrData] count]的查看次数不大于0,那么这可能有助于解决问题。如果它没有按下该委托回叫,则可能没有为集合视图正确设置委托。