Ios 在我的表中插入解析时的对象
我有一个带有内表的视图控制器,我想用保存在Parse上的数组填充它。要下载数据,我使用以下代码: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){
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完成之前运行)应该显示它未初始化。此示例使用表控制器,但我在视图控制器内有一个表,因此对我来说没有好处