简体   繁体   English

当我查询另一个类时,parse.com试图从User类获取值

[英]parse.com trying to get a value from a User class once i have queried another class

i'm trying to post the users location with his display name in the Table View. 我正在尝试在表视图中发布用户位置及其显示名称。 but all I'm getting in the data browser is the correct post but the display name is blank I'm trying to query the location Class and also the User Class which has the display name for the user 但是我在数据浏览器中得到的只是正确的帖子,但显示名称为空,我正在尝试查询位置类以及具有用户显示名称的用户类

// Configure the new event with information from the location.

CLLocationCoordinate2D coordinate = [location coordinate];
PFGeoPoint *geoPoint = [PFGeoPoint geoPointWithLatitude:coordinate.latitude    longitude:coordinate.longitude];
PFObject *object = [PFObject objectWithClassName:@"Location"];
[object setObject:geoPoint forKey:@"location"];
PFObject *UserObject = [PFObject objectWithClassName:@"_User"];
[[UserObject objectForKey:@"postedUser"] objectForKey:@"displayName"];

// Create relationship
[object setObject:[PFUser currentUser] forKey:@"postedUser"];

[UserObject setObject:[PFUser currentUser] forKey:@"displayName"];


PFACL *locatinACL = [PFACL ACLWithUser:[PFUser currentUser]];
[locatinACL setPublicReadAccess:YES];


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

  }
}];

anyone know what I'm doing wrong. 任何人都知道我在做什么错。 the display name is in the user class under displayName and i need it in the new post under displayName 显示名称在displayName下的用户类中,我需要在displayName下的新帖子中使用

the user save details saved under a form where the set has to fill in extra details after sign up 用户将详细信息保存在一个表格中,该表格必须在注册后填写额外的详细信息

NSString *saveName = UserNameText.text;
NSString *saveEmail = EmailAddressText.text;
NSString *saveMobile = MobileText.text;
NSString *saveAdd1 = Address1Text.text;
NSString *saveAdd2 = Address2Text.text;
NSString *savePostCode = PostCodeText.text;
NSString *saveCustTax = TaxiOrCust.text;



currentUserSave[@"displayName"] = saveName;
currentUserSave[@"email"] = saveEmail;
currentUserSave[@"mobile"] = saveMobile;
currentUserSave[@"address1"] = saveAdd1;
currentUserSave[@"address2"] = saveAdd2;
currentUserSave[@"postCode"] = savePostCode;
currentUserSave[@"customer"] = saveCustTax;

Forgive the long answer... I think I'm still slightly unclear about your data structure and what you're trying to achieve, so it seems to make the most sense if I clarify what your existing code is actually doing. 原谅冗长的答案...我想我仍然不太清楚您的数据结构以及您要实现的目标,因此,如果我弄清楚您现有的代码实际在做什么,这似乎是最有意义的。 Hopefully this will help you make any necessary adjustments. 希望这会帮助您进行必要的调整。

What you're currently doing 您目前正在做什么

PFObject *object = [PFObject objectWithClassName:@"Location"];
[object setObject:geoPoint forKey:@"location"];

Here you're creating a new Location object, and setting the geopoint you've created as its location . 在这里,您将创建一个新的 Location对象,并将您创建的地理点设置为其location If you have an existing Location object you want to update, you'll have to fetch that from Parse (unless you already have a variable / property for it). 如果您有一个现有的Location对象要更新,则必须从Parse中获取该对象(除非您已经有一个变量/属性)。

PFObject *UserObject = [PFObject objectWithClassName:@"_User"];

Here you're creating a new User object. 在这里您将创建一个新的 User对象。 I suspect you want to use the current user, rather than create a new one, however. 我怀疑您想使用当前用户,而不是创建一个新用户。 There's also a specific Parse object for users: PFUser - which you are using later on. 还有一个针对用户的特定Parse对象: PFUser您稍后将使用它。

[[UserObject objectForKey:@"postedUser"] objectForKey:@"displayName"];

This line does nothing. 该行不执行任何操作。 You're fetching UserObject 's postedUser property, and then fetching that user's displayName property. 您正在获取UserObjectpostedUser属性,然后获取该用户的displayName属性。 I don't think this is what you were intending. 我不认为这是您想要的。

[object setObject:[PFUser currentUser] forKey:@"postedUser"];
[UserObject setObject:[PFUser currentUser] forKey:@"displayName"];

This then updates the two new objects you created (your location and user objects), by setting two of their attributes to point to the current user. 然后,通过将其两个属性设置为指向当前用户,来更新您创建的两个新对象(您的位置和用户对象)。

PFACL *locatinACL = [PFACL ACLWithUser:[PFUser currentUser]];
[locatinACL setPublicReadAccess:YES];

These two lines create a new ACL which gives the current user write access, and everybody else read access. 这两行创建了一个新的ACL,该ACL授予当前用户写访问权限,其他人则具有读访问权限。 However, you're not applying this to your new location object. 但是,您没有将此应用到新的位置对象。

[object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
}
}];

Finally, this will save your new Location object. 最后,这将保存您的新Location对象。 However, the new User object you created will not be saved, as nothing else has a reference to it, and you're not calling save on it. 但是,您创建的新User对象将不会保存,因为其他任何对象都没有对该对象的引用,因此您不会在其上调用save。

What you might be trying to do 您可能想做什么

I think the code you're writing can probably be cut down to something along these lines: 我认为您正在编写的代码可能可以简化为以下几行:

// Create a new location object
PFObject *parseLocation = [PFObject objectWithClassName:@"Location"];

// Create a new PFGeopoint, and store it as the location's location.
CLLocationCoordinate2D coordinate = [location coordinate];
PFGeoPoint *geoPoint = [PFGeoPoint geoPointWithLatitude:coordinate.latitude    longitude:coordinate.longitude];
[parseLocation setObject:geoPoint forKey:@"location"];

// Store the current user and their display name as part of the location object
[parseLocation setObject:[PFUser currentUser] forKey:@"postedUser"];
[parseLocation setObject:[[PFUser currentUser] objectForKey:@"displayName"] forKey:@"displayName"];    

// Create ACL and save it to the location object
PFACL *locationACL = [PFACL ACLWithUser:[PFUser currentUser]];
[locationACL setPublicReadAccess:YES];
[parseLocation setACL:locationACL];

// Save the location object
[object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {

  }
}];

Is this closer to what you wanted? 这更接近您想要的吗?

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

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