Parse.com数据在iOS中获取“NULL”值

时间:2015-03-25 05:52:56

标签: ios objective-c parse-platform

我是parse.com的新手,并尝试从它获取数据的更多时间,但每次都给予NULL值。在这里,我的Parse表包含1.89k行,所以我想检查所有行并从中获取数据。对于数据提取,我写了像

这样的代码
-(void)getdata
{
NSMutableArray *allObjects = [[NSMutableArray alloc]init];
NSUInteger limit = 1000;
__block NSUInteger skip = 0;
PFQuery *query = [PFQuery queryWithClassName:@"MapInfo"];
[query whereKey:@"Type" equalTo:@"Business"];
[query whereKey:@"Admin" equalTo:self.bisusername];
[query setLimit: limit];
[query setSkip: skip];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        [allObjects addObjectsFromArray:objects];
        if (objects.count == limit) {
            skip += limit;
            [query setSkip: skip];
            [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
                [allObjects addObjectsFromArray:objects];
                self.qpinname=[allObjects valueForKey:@"GPIN"];
                NSLog(@"Qpin Array %lu",(unsigned long)[self.qpinname count]);
                self.locationArray=[allObjects valueForKey:@"Location"];
                self.latitude=[self.locationArray valueForKey:@"lat"];
                self.longitude=[self.locationArray valueForKey:@"lng"];
                self.address=[allObjects valueForKey:@"Address"];
                self.usernameArray=[allObjects valueForKey:@"AddedBy"];
                self.buildingNameArray=[allObjects valueForKey:@"BuildingName"];
                self.businessHourArray=[allObjects valueForKey:@"OfficeTiming"];
                self.parkingInfoArry=[allObjects valueForKey:@"Parking"];
                self.officenoArray=[allObjects valueForKey:@"DoorNumber"];
                NSLog(@"Office Array %@",self.officenoArray);
              hudView.hidden=TRUE;
            }];
        }
    }
    else
    {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];
}

当我写一个像

这样的代码
-(void)getdata
 {
PFQuery *query = [PFQuery queryWithClassName:@"MapInfo"];
[query whereKey:@"Type" equalTo:@"Business"];
[query whereKey:@"Admin" equalTo:self.bisusername];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error)
    {
        self.qpinname=[objects valueForKey:@"GPIN"];
        self.locationArray=[objects valueForKey:@"Location"];
        self.latitude=[self.locationArray valueForKey:@"lat"];
        self.longitude=[self.locationArray valueForKey:@"lng"];
        self.address=[objects valueForKey:@"Address"];
        self.usernameArray=[objects valueForKey:@"AddedBy"];
        self.buildingNameArray=[objects valueForKey:@"BuildingName"];
        self.businessHourArray=[objects valueForKey:@"OfficeTiming"];
        self.parkingInfoArry=[objects valueForKey:@"Parking"];
        self.officenoArray=[objects valueForKey:@"DoorNumber"];
    }
    else
    {
        NSString *errorString = [[error userInfo] objectForKey:@"error"];
        NSLog(@"Error: %@", errorString);
    }
}];
}

然后我从表中获得了价值,但它只给我一个页面的价值,我希望从我的整个表格中得到价值请给我解决方案吧 感谢。

1 个答案:

答案 0 :(得分:0)

您根本没有迭代对象数组。你正在做这样的事情:

self.qpinname=[allObjects valueForKey:@"GPIN"];

allObjects是ARRAY而不是字典。您需要迭代数组并以这种方式访问​​对象。请记住,对象属于从Parse.com下载的PFObject类型。 e.g:

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
                [allObjects addObjectsFromArray:objects];
                for(PFObject *object in allObjects) {

                //now you can access things,e.g....
                self.locationArray=object[@"Location"]; 
                //and so on...



               }

            }];

那应该解决它。确保你也在循环中使用PFObject。