如何正确处理iOS中视图控制器中数据的持久性和状态警报

时间:2012-09-13 23:11:22

标签: ios rest asynchronous uitextview

我在iOS应用中有2个文本视图用于更新用户密码。我使用RESTful Web服务在用户单击确认按钮后将数据保存到远程数据库。

如果传输出现问题或输入数据在服务器端验证失败,我该如何与用户沟通?

我不想让这个及时的流程继续等待用户。我希望使服务异步,并在用户点击另一个视图后提醒用户状态。

我将如何做到这一点?

谢谢!

1 个答案:

答案 0 :(得分:1)

将请求委托设置为您的UIApplication委托

如果使用ASIHTTPRequest,请使用失败消息

设置userInfo字典
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:@""];
[request setUserInfo:[NSDictionary dictionaryWithObject:@"Password reset failed" forKey:@"failureAlertMessage"];
[request setDelegate:[[UIApplication sharedApplication] delegate]];

使您的UIApplication委托符合请求委托协议(例如,ASIHTTPRequestDelegate)

在UIApplication委托中,使用请求中包含的信息显示错误消息

- (void)requestFailed:(ASIHTTPRequest *)request
{
    if([[request userInfo] objectForKey:@"failureAlertMessage"]){
        //Do the alert
    }
}