我正在檢查重複的用戶名方法。基本上,在註冊過程中將使用此方法來檢查重複的用戶名。我從我的URL中獲得了所有充滿用戶名的JSON。最主要的是我的方法似乎沒有工作。匹配JSON用戶名和UITextField
這裏是我的代碼
- (void)viewDidLoad
{
[super viewDidLoad];
// DIOSSession *session = [DIOSSession sharedSession];
// [session user];
// [[DIOSSession sharedSession] user];
[self makeRequestJSON];
[self.txtPasswordRegister addTarget:self action:@selector(checkTextField:) forControlEvents:UIControlEventEditingChanged];
[self.txtPaasswordRegisterReEnter addTarget:self action:@selector(checkTextField:) forControlEvents:UIControlEventEditingChanged];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)makeRequestJSON
{
NSURL *url = [NSURL URLWithString:@"http://localhost/drupal/rest/user.json"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id responseObject)
{
_myJson = responseObject;
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id responseObject)
{
NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
}];
[operation start];
}
- (IBAction)ChkUsername:(id)sender {
[self makeRequestJSON];
NSString *match = [_myJson valueForKey:@"name"];
NSLog(@"match is %@", match);
if([self.txtUsernameRegister.text isEqualToString: match]){
[self alertStatus:@"Duplicate Username" :@"Pick another Username" :0];
}else {
[self alertStatus:@"You can use this username" :@"Yeahhh" :0];
}
}
這裏是我的JSON,我從NSLog的了。
pae1344,
pae12,
pae13,
mai,
kbank1,
kbank,
fuji1,
fuji,
admin,
""
你需要存儲所有josn響應數組,然後匹配您當前的文本域價值與陣列的每個對象...但作爲我個人的經驗,它更好地傳遞用戶名到服務器和服務器將返回該用戶名是否存在或不? – Apple