查询对象标题到标签

时间:2014-01-22 20:29:46

标签: ios arrays label parse-platform

我有一个Parse查询,用于收集您所在区域中最近的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个?我做错了吗?

1 个答案:

答案 0 :(得分:0)

您的问题是EventTitle1.text = EventTitle;,因为您明确引用了标签。您应该做的是按顺序更新标签。这可以通过在数组中使用标签(可能是IBOutletCollection)并使用迭代索引来完成。或者您可以标记所有标签,然后查找它们(再次使用迭代索引)。

但是,您的预期解决方案并不简单,也无法扩展。使用表视图会更好(Parse SDK甚至可以让您轻松地从查询中填充表视图)。