我在我的用户注册应用程序中使用了以下代码来与远程数据库进行交互。
-(IBAction)checkFirstName:(UITextField*)textField
{
NSURL *url = [NSURL URLWithString:@"http://mysite.com"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue: firstName.text forKey:@"firstName"];
[request setDelegate:self];
[request didReceiveDataSelector];
[request startAsynchronous];
firstName.rightViewMode = UITextFieldViewModeAlways;
if (receivedData==0)
{
UIImage *image = [UIImage imageNamed:@"close.png"];
[button setImage:image forState:UIControlStateNormal];
firstName.rightView = button;
}
}
'firstName' 是我用来从用户那里获取输入的文本字段值。我使用以下方法从数据库接收响应
-(void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data
{
receivedData = [request responseData];
[receivedData appendData:data];
receivedString = [[NSString alloc] initWithData:receivedData
encoding:NSUTF8StringEncoding];
}
'receivedData' 是全局声明的 NSData 对象。我必须将“responseData”设为 0 或 1,它们将存储在变量“receivedData”中。
- 如何检查“receivedData”对象的值(0 或 1)?
- checkFirstName: 将在 uitextfield Editing DidEnd 事件上触发操作。
我们可以使用 responseData==0 吗?请给我建议一个解决方案...等待紧急响应..