使用parse和iOS SDK检索相关数据 [英] Retrieve related data with parse and ios sdk
问题描述
我只是想使用Parse将相关数据检索到我的应用程序中,但是遇到了一些问题. 我有2个表格,旅行和城市,旅行有一个相关的字段,称为origin-city.我在数据浏览器中使用了一个指针来将它们关联起来.
I'm just trying to retrieve related data into my app with Parse but I'm getting some problems. I have 2 tables, Travel and City, Travel has a related field called origin-city. I'm using a pointer in Data Browser to relate both of them.
所以我正在使用 queryForTable 方法
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
[query includeKey:@"origin-city"];
return query;
}
我总是得到指针ID,但没有得到我真正需要的城市名称. 这是执行此操作的正确方法吗?我如何获取城市名称?
And I'm always getting the pointer Id but not the City name that's what I really need. This is the proper method for doing this ? how could I retrieve the name of the city ?
修改
当我打印来源城市时,我会得到 City:M0PwR0OiLj:(null),其中M0PwR0OiLj是City的objectId,在这里我需要名称
When I print the origin city I'm getting City:M0PwR0OiLj:(null) where M0PwR0OiLj is the objectId for City, here I need the name
非常感谢
推荐答案
我假设您使用的是PFQueryTableViewController
,因为方法queryForTable
属于该方法.指出查询已在进行中的错误是因为PFQTVC在后台触发了查询,因此在您的情况下无法进行findObjectsInBackgroundWithBlock
回答.
I assume you are using a PFQueryTableViewController
, as the method queryForTable
belongs to that. The error stating that a query is already in progress is because the query is fired behind the scenes by the PFQTVC, so the answer asking to do a findObjectsInBackgroundWithBlock
is not possible in your case.
使用此特殊的表视图控制器,还向cellForRowAtIndexPath
传递了PFObject
,这是与行匹配的对象.
With this special table view controller, the cellForRowAtIndexPath
is also passed a PFObject
, which is the object to matching the row.
要获取来自相关对象的城市名称,请在cellForRowAtIndexPath
中使用以下代码:
To get the city name, which is from related object, you use this code in cellForRowAtIndexPath
:
PFObject *city = object[@"origin-city"];
[cell.textLabel setText:city[@"name"]; // The name column from the City class
这篇关于使用parse和iOS SDK检索相关数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!