Objective c UIAlertView没有';不显示
我正在测试服务器对用户名真实性的响应。若服务器响应为“用户缺席”,则将弹出UIAlertViewObjective c UIAlertView没有';不显示,objective-c,uialertview,Objective C,Uialertview,我正在测试服务器对用户名真实性的响应。若服务器响应为“用户缺席”,则将弹出UIAlertView - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSString *responseString1 = [[NSString alloc] initWithData:responseData1 encoding:NSUTF8StringEncoding]; NSLog(@"%@",response
- (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,如果用户名和密码字段都丢失,它会发出警报。然而,这一观点起了作用
而不是提前…您得到的响应是“用户缺席”,而不是用户缺席。(即带引号的字符串) 除非在
init
或dealloc
方法中,否则不要直接使用支持变量(_user缺席)
像这样试试
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];
}
希望这对您有所帮助…您的
UIAlertView
似乎设置不正确
当您只需要一个声明时,在末尾有两个nil
声明
[[UIAlertView alloc] initWithTitle:@"Error" message:@"1. Display Name missing.\n2. Password missing." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
这似乎是一个奇怪的错误,但也许这就是原因 您收到的字符串是否被引用?从
NSLog
行中可以看出,字符串被双引号包围,这不是您测试的目的。哪里定义了_user缺席?另外,您是否也在if语句中登录,看看它是否经过了那里?我复制了第一个UIAlertView,它在不只是为了测试可操作性的UIAlertView上工作。。。
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Set Your Message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];