2014-01-22 40 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甚至为您提供了一种从查询中填充表格视图的简单方法)。