Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在我的表中插入解析时的对象_Ios_Parse Platform_Nsmutablearray_Pfquery - Fatal编程技术网

Ios 在我的表中插入解析时的对象

Ios 在我的表中插入解析时的对象,ios,parse-platform,nsmutablearray,pfquery,Ios,Parse Platform,Nsmutablearray,Pfquery,我有一个带有内表的视图控制器,我想用保存在Parse上的数组填充它。要下载数据,我使用以下代码: PFQuery *query = [PFQuery queryWithClassName:@"myClass"]; [query whereKey:@"X" equalTo:@"Y"]; [query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) { if(error==nil){

我有一个带有内表的视图控制器,我想用保存在Parse上的数组填充它。要下载数据,我使用以下代码:

 PFQuery *query = [PFQuery queryWithClassName:@"myClass"];
[query whereKey:@"X" equalTo:@"Y"];
[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
    if(error==nil){

       myArray=[object objectForKey:@"Z"];
       NSLog(@"%@",myArray);
    }

}];
}
现在我将它显示在parse上的数据中。但是如果我使用数组填充表,它总是空的。我使用了
NSLog
,我看到在方法
之外[query getFirstObjectInBackgroundWithBlock:^(PFObject*object,NSError*error)
我的数组总是空的。
如何帮助我?

从远程数据库获取数据需要一点时间。采用块参数的解析函数异步运行。请参阅稍加修改的代码中的注释

[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
    if(error==nil){
       // this appears first in the file, but runs later
       // after the request is finished
       myArray=[object objectForKey:@"Z"];
       NSLog(@"%@",myArray);
       // tell our view that data is ready
       [self.tableView reloadData];
    }
}];

// this appears second in the file, but runs right away, right
// when the request is started
// while execution is here, the request isn't done yet
// we would expect myArray to be uninitialized

请确保,在数据源方法中,例如
numberOfRows
回答
myArray.count
。并使用数组
myArray[indexPath.row]中的数据
在构建表视图单元格时。

您只返回了从Parse中找到的第一个对象,而不是数组。您可能应该使用不同的方法从Parse中获取数据?您是否看过他们的示例:?您知道我可以使用的方法?感谢您澄清。
NSLog(@“%@”,myArray)
在完成块内显示期望值?当然,块后的NSLog(在getFirst完成之前运行)应该显示它未初始化。此示例使用表控制器,但我在视图控制器内有一个表,因此对我来说没有好处