连接服务器时如何显示警告对话框?

时间:2013-12-10 17:36:10

标签: ios objective-c

异步请求已发送到服务器,这是我的连接委托。 在RKYLoginDelegate.m文件中,我发出警告,告诉用户该成员在接收数据时正在验证。

didReceivedData

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [_receivedData appendData:data];

    loginAlertView = [[UIAlertView alloc] initWithTitle:@"message"
                                                message:@"verifying member..."
                                               delegate:self
                                      cancelButtonTitle:nil
                                      otherButtonTitles:nil];
    [loginAlertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];

    NSLog(@"Received data: %@", [[NSString alloc] initWithData:_receivedData encoding:NSUTF8StringEncoding]);
}

并在完成加载数据时,如果没有返回,则显示错误消息。 didFinishLoading

- (void)connectionDidFinishLoading:(NSURLConnection *)connection;

在代码中,它将验证返回状态和解析值,如果没有响应,则提醒对话框通知用户错误消息

if ([jsonDataDictionary count] > 0) {

    // add member into data
    RKYMemberManager *rkyMemberManager = [RKYMemberManager new];
    [rkyMemberManager addMember:jsonDataDictionary];

    // navigate to main
    UIStoryboard *rkyMainStoryboard = [UIStoryboard storyboardWithName:@"RKYMainStoryboard" bundle:nil];

    RKYMainViewController *rkyMainViewController =
    [rkyMainStoryboard instantiateViewControllerWithIdentifier:@"RKYMain"];

    [[[UIApplication sharedApplication] delegate].window.rootViewController.navigationController presentViewController:rkyMainViewController animated:YES completion:nil];
}
else {
    UIAlertView *alertView = [[UIAlertView alloc]
                              initWithTitle:@"message"
                              message:@"Cannot login!"
                              delegate:self
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
    [alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
    [alertView show];
    NSLog(@"cannot login");
}

那些警告对话框确实显示了它的消息,但会导致错误:

Thread 1:EXC_BAD_ACCESS(code=2, address=0xc)

作为标题,我做得对吗? 如果是,如何解决造成的问题?

0 个答案:

没有答案