UIAlert是否需要某种延迟?

时间:2009-07-15 10:18:57

标签: iphone objective-c

尝试在互联网不可用时提醒用户(并在他们解除消息时重试)。屏幕稍微变暗(准备警报),但警报从不显示。

while循环是否干扰警报?

-(NSArray*)getResponse:(NSString*)page {
NSError *error;
NSURLResponse *response;
NSData *dataReply;
NSString *stringReply;
NSString *legalAddressURL;
NSArray *separatedData;
legalAddressURL = [NSString stringWithFormat:@"%@%@", SERVER, 
                   [page stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: legalAddressURL]];
[request setHTTPMethod: @"GET"];
dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
while ([error code]){
    if (isNetAvailable){
        UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Internet Connection" 
            message:@"Server is down" delegate:self cancelButtonTitle:@"Try again" 
            otherButtonTitles:nil] autorelease];
        [alert show];
        dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    } else {
        UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Internet Connection" 
            message:@"No access to net" delegate:self cancelButtonTitle:@"Try again" 
            otherButtonTitles:nil] autorelease];
        [alert show];
        dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    }
}
stringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
separatedData = [stringReply componentsSeparatedByCharactersInSet:
                 [NSCharacterSet characterSetWithCharactersInString:@","]];
return separatedData;

}

1 个答案:

答案 0 :(得分:1)

使用 [提示显示] 显示提醒后,您应该退出 getResponse 方法,因为内部消息循环应该继续。

您不能简单地继续循环并显示警报。

我可能错了,但我很确定这就是原因。