我收到了此警告,找不到解决方法。在下面的代码中,我尝试从parse.com搜索用户名。错误位于menuItem.text行。有人可以帮我解决这个错误。谢谢。 这是我的代码。
@interface FriendsScene()
@property(nonatomic) NSArray *user;
@end
-(void)didMoveToView:(SKView *)view {
PFQuery *query = [PFUser query];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
[query whereKey:@"username" containsString:@"test"];
self.user = [[query findObjects]valueForKey:@"username"];
[self addNode];
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
-(void)addNode{
// add menu background
menuNode = [SKSpriteNode spriteNodeWithColor:[SKColor lightGrayColor] size:CGSizeMake(200, 100)];
menuNode.name = @"menuNode";
menuNode.position = CGPointMake(100, 0);
menuNode.zPosition = 10;
[self addChild:menuNode];
float yPos = -450;
for (int i = 0; i < 2; i++) {
SKLabelNode *menuItem = [SKLabelNode labelNodeWithFontNamed:@"HelveticaNeue"];
menuItem.name = [NSString stringWithFormat:@"menuItem-%i",i];
menuItem.text = [NSString stringWithFormat:@"%@",[self.user objectAtIndex:i]];
menuItem.fontSize = 20;
menuItem.fontColor = [SKColor redColor];
menuItem.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter;
menuItem.verticalAlignmentMode = SKLabelVerticalAlignmentModeCenter;
menuItem.position = CGPointMake(0, yPos);
menuItem.zPosition = 25;
[menuNode addChild:menuItem];
yPos += 40;
}
}
答案 0 :(得分:1)
要查找具有特定用户名的用户,您只需要在PFUser类上进行一次查询。使用您希望匹配的名称限定该查询。结果将是匹配的对象数组:
PFQuery *query = [PFUser query];
[query whereKey:@"username" containsString:@"test"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
if (objects.count) {
self.user = objects[0];
} else {
// the query worked, but no users were found with that username
}
[self addNode];
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];