简体   繁体   中英

UIAlertView doesn't show

I am testing for server response on username authenticity. If server responded with "User absent" a UIAlertView is meant to pop up.

- (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];
    }

I typed in some random username and password to fake an error but the alert view just did not pop up. Did NSLog twice on the data from server.

This is the log output:

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

I have another UIAlertView prior to requesting the data from the server, which alerts if both the username and password field is missing. That AlertView worked however.

  1. Any pointers on this issue?
  2. I understand AlertView can be a sore eyes. Is there anyway to alert users without using AlertView?

Than in advance...

Your getting the response as "User absent" instead of User absent.(ie string with quotes)

Do not use the backing variables(_userAbsent) straightly , except in init or dealloc methods.

Try like this...

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];
}

Hope this will helpful for you...

It looks like your UIAlertView isn't setup properly.

You have two nil declarations at the end when you only need one.

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

It would seem a strange error but perhaps that is the cause?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM