简体   繁体   English

解析PFUser CurrentUser返回Null

[英]Parse PFUser CurrentUser Returning Null

I save a few objects in the _User class in parse, such as displayname, gender, and bio. 我在_User类中保存了一些对象以进行解析,例如显示名,性别和生物。 A simple user profile. 一个简单的用户配置文件。 I'm having difficulty retrieving them. 我很难找回它们。 I tried with many types of queries with no luck. 我尝试了很多没有运气的查询。 So I figured if you could get the username by doing this: 所以我想知道是否可以通过执行以下操作获得用户名:

self.username.text = [NSString stringWithFormat:@"@""%@",[[PFUsercurrentUser]valueForKey:@"username"]];

You should be able to get other objects that are stored in _User right? 您应该能够获取存储在_User中的其他对象吗? Well I tryed this to get the display name: 好吧,我尝试这样做以获得显示名称:

self.name.text = [NSString stringWithFormat:@"%@",[[PFUser currentUser]valueForKey:@"name"]]; 

And I get (null) printed out on the label, except in the data browser there is a value there. 我在标签上打印了(空),除了在数据浏览器中有一个值。 I'm really in need of some assistance this has been a problem that's taking me a while to figure it out. 我确实需要一些帮助,这是一个问题,需要我花点时间才能弄清楚。 Thanks! 谢谢!

You have mentioned two lines in your code:- 您在代码中提到了两行:

//Have modified this line //已修改此行

In this line valueForKey you are passing @"username" 在此行valueForKey中,您传递@“ username”

self.username.text = [NSString stringWithFormat:@"%@",[[PFUser currentUser]valueForKey:@"username"]];

In this line valueForKey you are passing @"name" 在此行valueForKey中,您传递@“ name”

self.name.text = [NSString stringWithFormat:@"%@",[[PFUser currentUser]valueForKey:@"name"]]; 

Now in above two line both are having two separate keys username and name. 现在,在上面的两行中,两个都有两个单独的键用户名和名称。 So just check the valid key like that below if you are not sure which is valid, if below any of line prints value then use that key for setting the value in your label:- 因此,如果不确定哪个有效,只需检查下面的有效键,如果行中的任何一行打印值低于该值,则可以使用该键在标签中设置该值:-

NSLog(@"%@",[[PFUser currentUser]valueForKey:@"username"]);
NSLog(@"%@",[[PFUser currentUser]valueForKey:@"name"]);

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

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