2013-03-28 101 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];