2015-02-23 45 views
0
@implementation StudyViewController 


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

顯示設置uimages的...... 基本上我通過afnetworking收到responseobject。 然後將數據存儲在稱爲arData不能在uicollectionview

   ............ 
       ........... 

      [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); 
}]; 

全局定義的nsmutable陣列}

 #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路徑,如下所示。 其餘參數(超文本,UrlKey,portNumber,分隔符)通過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 - 我似乎無法進去

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

2-在控制檯中的NSLog輸出任何東西,我不能顯示任何圖像,即使我知道從Web服務接收到的參數是否正確( &我的NSLog他們沒有任何問題,當viewDidLoad中。

任何幫助,將不勝感激。

謝謝。

+0

檢查你的共享控制器是否存在? – Wain 2015-02-23 18:57:13

+0

arrData nsmutable在Global.h中定義&它存在於這個視圖中controllerStudyViewController – 2015-02-24 01:17:23

回答

1

您應該首先看到致電numberOfItemsInSection。如果您可以在那裏設置斷點(或NSLog),並且[[[Global sharedGlobal]arrData] count]的查看計數不小於0,那麼這可能有助於解決問題。如果它沒有觸及該委託回叫,那麼可能代表沒有正確設置collectionview。

+0

謝謝你的回覆。 我試過NSLog(@「%lu」,(unsigned long)[[[[Global sharedGlobal] arrData] count]); 這是說代碼永遠不會被執行? – 2015-02-24 01:12:47

+0

我實際上可以看到count = 5。仍然無法獲取圖像。 在我的scenerio中,如何設置代表和數據源?有點與這一個混淆。我是否需要將委託和數據源設置爲自己?謝謝 – 2015-02-24 05:16:50

+0

當你看到它永遠不會被執行時,你在哪裏放置NSLog(@「%lu」,(unsigned long)[[[Global sharedGlobal] arrData] count])'。 – 2015-02-24 10:51:53