我在 iOS 应用程序中有 2 个 TextView 用于更新用户密码。我正在使用 RESTful Web 服务在用户单击确认按钮后将数据保存到远程数据库。
如果传输过程中出现问题或者输入数据在服务器端验证失败,我如何将此信息传达给用户?
我不想让用户在这个及时的过程继续等待。我想让服务异步并提醒用户状态,即使他们单击了另一个 View 也是如此。
我该如何实现这个目标?
谢谢!
最佳答案
将请求委托(delegate)设置为您的 UIApplication 委托(delegate)
如果使用 ASIHTTPRequest,请使用失败消息设置 userInfo 字典
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:@""];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"Password reset failed" forKey:@"failureAlertMessage"];
[request setDelegate:[[UIApplication sharedApplication] delegate]];
使您的 UIApplication 委托(delegate)符合请求委托(delegate)协议(protocol)(例如 ASIHTTPRequestDelegate)
在 UIApplication 委托(delegate)中,使用请求中包含的信息来显示错误消息
- (void)requestFailed:(ASIHTTPRequest *)request
{
if([[request userInfo] objectForKey:@"failureAlertMessage"]){
//Do the alert
}
}
关于ios - 如何在iOS中正确处理 View Controller 中的数据持久性和状态警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12416094/