我正在使用Parse,我正在从数据浏览器中检索一个名为“用户名”的类。我得到了类中的所有对象,并将它们存储在一个数组中。然后我想在数组中搜索用户名,以便用户可以登录。我会为密码做同样的事情。这是我的代码:
- (IBAction)login:(id)sender
{
if ([usernameLogin.stringValue isEqualTo:@""] || [passwordLogin.stringValue isEqualTo:@""]) {
NSBeginAlertSheet(@"Error", @"OK", nil, nil, self.window, self, @selector(sheetDidEnd:resultCode:contextInfo:), NULL, NULL, @"Please fill in all fields.");
}
/* retrieve user from parse db */
PFQuery *usernameQuery = [PFQuery queryWithClassName:@"usernames"];
[usernameQuery findObjectsInBackgroundWithBlock:^(NSArray *usernames, NSError *error) {
NSString *userString = [NSString stringWithFormat:@"%@", usernameLogin.stringValue];
NSLog(@"USERS:\n %@", usernames);
int i;
for (i = 0; i < [usernames count]; i++) {
NSString *userFind = [usernames objectAtIndex:i];
if ([userString isEqualToString:userFind]) {
NSLog(@"FOUND!!!");
}
}
/*
if ([usernames indexOfObject:usernameLogin.stringValue]) {
NSLog(@"User: '%@' was found successfully!", usernameLogin.stringValue);
} else {
NSLog(@"User: '%@' doesn't exist in database, or password was incorrect!", usernameLogin.stringValue);
}
*/
}];
gameCont = [[CSGameController alloc] initWithWindowNibName:@"CSGameController"];
[gameCont showWindow:self];
[gameCont.window makeKeyAndOrderFront:nil];
_window.isVisible = false;
}
谁能解释我做错了什么?我正在搜索数据库以查看输入的用户是否存在。我设置了一个测试用户,它仍然说它不存在。非常感谢!添加:
int i;
for (i = 0; i < [usernames count]; i++) {
NSString *userFind = [usernames objectAtIndex:i];
NSLog(@"UserFind class = %@, value = %@", [userFind class], userFind);
}
输出:
[2438:303] UserFind class = PFObject, value = <usernames:kx7aG2xfkX:(null)> {
username = ryan;
}