2014-01-22 38 views
0

我有一個分析查詢運行以收集您所在地區最近的10個拱廊,我試圖讓他們在10個單獨的標籤中顯示這些對象標題。我有下面的代碼收集10最接近,並記錄他們,我試圖開始顯示標籤objectId,但無法弄清楚如何顯示它們,而不僅僅是1.任何建議?查詢對象標題到標籤

PFQuery *query = [PFQuery queryWithClassName:@"Arcade"]; 
CLLocation *currentLocation = locationManager.location; 
PFGeoPoint *userLocation = 
[PFGeoPoint geoPointWithLatitude:currentLocation.coordinate.latitude 
         longitude:currentLocation.coordinate.longitude]; 
query.limit = 10; 
[query whereKey:kPAWParseLocationKey nearGeoPoint:userLocation withinMiles:kPAWWallPostMaximumSearchDistance]; 
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
    if (!error) { 
     // The find succeeded. 
     NSLog(@"Successfully retrieved %d scores.", objects.count); 
     // Do something with the found objects 
     for (PFObject *object in objects) { 
      NSLog(@"%@", object.objectId); 
      NSString *EventTitle = object.objectId; 
      EventTitle1.text = EventTitle; 
      for (UIImageView *imageView in self.imageViews) { 
       __block UIImage *MyPicture = [[UIImage alloc]init]; 
       PFFile *imageFile = [object objectForKey:@"test"]; 
       [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error){ 
        if (!error) { 
         MyPicture = [UIImage imageWithData:data]; 
         imageView.image = MyPicture; 
        } 
       }]; 
      } 
      for (UILabel *EventLabel in self.EventTitles){ 
       EventLabel.text = object.objectId; 
      } 
     } 

更新:我創建了兩個收集出口,然而,當他們展示他們只顯示查詢的最終目標,而不是他們的全部10個?難道我做錯了什麼?

+0

爲什麼選擇標籤?爲什麼不是桌子視圖? – Wain

回答

0

您的問題是EventTitle1.text = EventTitle;,因爲您明確引用標籤。你應該做的是按順序更新標籤。這可以通過將數組中的標籤(可能是IBOutletCollection)並使用迭代索引來完成。或者你可以標記所有標籤,然後查看它們(再次使用迭代索引)。

但是,您的預期解決方案並不簡單,也不會擴展。使用表格視圖會更好(Parse SDK甚至爲您提供了一種從查詢中填充表格視圖的簡單方法)。