解析关系字符串

时间:2015-08-04 12:26:09

标签: ios xcode parse-platform nsstring

我正在开发一款解析数据的iOS应用 我有一个名为@" name"这个类包含一个字符串列[name] 还有一个名为@"电子邮件"这个类包含一个字符串列[email] 该课程已经相关,没有问题

在另一个ViewController中有两个TextField和一个按钮,在TextField上用户输入一个有效的名称字符串(名称)

按钮显示应在第二个TextField中显示与输入的名称关联的电子邮件。我想关联这些数据。

//relation class
PFObject *data = [PFObject objectWithClassName:@"nameContactMe"];

data[@"name"] = _name.text;

PFObject *DataRequest = [PFObjec objectWithClassName:@"mailContactMe"];

DataRequest[@"email"] = _email.text;

DataRequest[@"relation"] = data;

[DataRequest saveInBackground];

灾难

 //get relation 

- (IBAction)GetDate:(id)sender {

PFRelation *relation = [user relationForKey:@"relation"];

[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

    if (succeeded) {

        // The post has been added to the user's likes relation.

    } else {

        // There was a problem, check error.description

    }

}];

PFObject *data = _Visitor.text = @"relation";

[data fetchIfNeededInBackgroundWithBlock:^(PFObject *post, NSError *error) {

    emailField.text = data[@"email"];



    // do something with your title variable

}];





}

1 个答案:

答案 0 :(得分:0)

我认为您应该使用PFQuery来获取所需的电子邮件:

PFQuery *query = [PFUser query];
[query whereKey:@"name" equalTo:name];
[query getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {

   NSString  *email = [object valueForKey:@"email"];
}

如果您想要获取当前用户的电子邮件(登录用户),那么您可以使用:

NSString  *email =[[PFUser CurrentUser] [@"email"];