2013-03-28 104 views
0

我正在测试用户名真实性的服务器响应。如果服务器响应“用户缺席”,则意味着弹出一个UIAlertView。UIAlertView不显示

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 
    NSString *responseString1 = [[NSString alloc] initWithData:responseData1 encoding:NSUTF8StringEncoding]; 

    NSLog(@"%@",responseString1); 

    NSString *response = responseString1; 
    NSLog(@"%@",response); 

    if ([response isEqualToString:@"User absent"]) { 
     _userAbsent = [[UIAlertView alloc]initWithTitle:@"Error" message:@"1. Display Name missing.\n2. Password missing." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
     self.userAbsent.delegate = self; 

     [_userAbsent show]; 
    } 

我输入了伪造的错误一些随机的用户名和密码,但警报视图只是没有弹出。 NSLog是否从服务器获得两次数据。

这是日志输出:

2013-03-28 20:59:35.542 SimpleTable[1429:f803] "User absent" 
2013-03-28 20:59:35.542 SimpleTable[1429:f803] "User absent" 

我还有一个UIAlertView中之前,从服务器,它提醒如果两个用户名和密码字段缺少请求数据。该AlertView工作但是。

  1. 在这个问题上的任何指针?
  2. 我知道AlertView可以是一个痛眼。无论如何提醒用户不使用AlertView?

比预先...

+0

您收到的字符串是否被引用?它从'NSLog'行看起来是该字符串被双引号包围,这不是你正在测试的内容。 – bdesham

+0

_userAbsent在哪里定义? – Josiah

+0

另外,你是否记录你的if语句,看看它是否甚至经过那里? – Josiah

回答

2

你得到响应,“用户不存在”,而不是用户不存在的。(带引号即字符串)

不要使用后盾变量( _userAbsent)直接,除了initdealloc方法。

尝试像这样...

NSString *strResponse = @"\"User absent\""; 
if ([response isEqualToString:strResponse]) { 

    self.userAbsent = [[UIAlertView alloc]initWithTitle:@"Error" message:@"1. Display Name missing.\n2. Password missing." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

    [self.userAbsent show]; 
} 

希望这能对你有帮助...

0

它看起来像你的UIAlertView未正确设置。

当你只需要一个时,你有两个nil声明。

[[UIAlertView alloc] initWithTitle:@"Error" message:@"1. Display Name missing.\n2. Password missing." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

这似乎是一个奇怪的错误,但也许这是原因?

+0

我复制了第一个工作过的UIAlertView,它不仅仅是为了测试可用性...... –

0
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Set Your Message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
[alert show]; 
[alert release];