사용자가 로그인 버튼을 눌렀을 때 사용자가 사용자 이름과 비밀번호를 입력했을 때 경고보기에 특정 이름을 표시하고 싶습니다. 제발 도와주세요. 미리 감사드립니다. 도움을 주시면 감사하겠습니다.
- (IBAction)LoginPressed:(id)sender
{
if (managedObjContext == nil) {
AppDelegate *app = (AppDelegate*)[UIApplication sharedApplication].delegate;
managedObjContext= app.managedObjectContext;
}
NSFetchRequest *request =[[NSFetchRequest alloc]init];
NSEntityDescription *rocordTableEntity = [NSEntityDescription entityForName:@"RecordTable" inManagedObjectContext:managedObjContext];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"username==% @AND password==%@",L_usernameField.text,L_passwordField.text];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"firstname=%@",[managedObjContext valueForKey:@"firstname"]];
[request setEntity:rocordTableEntity];
[request setPredicate:predicate];
[request setPredicate:pred];
NSError *error;
NSArray *arrarforCheckingUserANDPass = [managedObjContext executeFetchRequest:request error:&error];
NSString *value = [arrarforCheckingUserANDPass valueForKey:@"firstname"];
if (arrarforCheckingUserANDPass.count != 0) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Welcome" message:value d elegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
}
else{
NSLog(@"not matched");
}
}
두 번째 setPredicate
는 첫 번째를 덮어 씁니다. 당신은 그것을 필요로하지 않습니다. 전체 엔티티를 얻은 다음 간단히 firstName
속성에 액세스합니다 . 첫 번째 술어에 잘못된 구문이 있습니다.
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"RecordTable"];
request.predicate = [NSPredicate predicateWithFormat:
@"username==%@ AND password==%@",L_usernameField.text,L_passwordField.text];
NSArray *result = [self.managedObjectContext executeFetchRequest:request error:nil];
RecordTable *user = result.firstObject;
if (user) {
NSLog(@"The first name is %@.", user.firstName);
}
BTW, 왜 당신의 방법이 대문자로 시작합니까? 그것은 매우 나쁜 습관입니다. 귀하의 법인 이름도 재앙입니다. "RecordTable"은 선택할 수있는 최악의 엔티티 이름에 관한 것입니다. 사용자 인 경우 "사용자"라고합니다. 관례에 따라, 나는 당신의 firstName 속성도 낙타로 덮었습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다