简体   繁体   English

Parse.com获取关系数据iOS

[英]Parse.com getting relationship data iOS

So I am working with Parse.com for an iOS app with relational data. 因此,我正在使用Parse.com来开发具有关系数据的iOS应用。 I got the app set up so its saving relational data in 2 classes (user and agent). 我设置了应用程序,因此将其关系数据保存在2个类(用户和代理)中。 What I am trying to do is display the "agent" info (in parse the columns are name string, and email string) in a some labels so when logged in the app the "agent" info assigned to the user shows up. 我正在尝试做的是在一些标签中显示“代理”信息(在解析中,列为名称字符串和电子邮件字符串),以便在登录应用程序时显示分配给用户的“代理”信息。 What I have is 我有的是

    self.agentRelation = [[PFUser currentUser] objectForKey:@"agentRelation"];
    PFQuery *query = [self.agentRelation query];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error %@", error);
        }
        else {
            self.agent = objects;

        }
    }];

this should get the info from parse but not sure how to spit it out for instance the Name string into a label outlet from here. 这应该从解析中获取信息,但不确定如何从此处将其吐出,例如,名称字符串。

Your line self.agent = objects; 您的行self.agent = objects; are incorrect. 是不正确的。 "objects" here are an array of objects resulting from the query. 这里的“对象”是查询产生的对象数组。 In your case, this is an array with only 1 object (the agent object). 在您的情况下,这是一个只有1个对象(代理对象)的数组。 You need to get the object from the list, and then get the properties from that object. 您需要从列表中获取对象,然后从该对象获取属性。

I've changed your code so that you get a reference to the agent object. 我更改了您的代码,以便获得对代理对象的引用。 I also set the name and email from the agent object on UILabels (that you need to create, or replace with the labels you have created already, if any). 我还通过UILabels上的代理对象设置了名称和电子邮件(您需要创建该名称和电子邮件,或者将其替换为已经创建的标签(如果有的话))。

self.agentRelation = [[PFUser currentUser] objectForKey:@"agentRelation"];
PFQuery *query = [self.agentRelation query];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (error) {
        NSLog(@"Error %@", error);
    }
    else {
        PFObject *agent = [objects lastObject];
        self.agentNameLabel.text = agent[@"name];
        self.agentEmailLabel.text = agent[@"email];
    }
}];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM