0
インターネットが利用できないときにユーザーに警告します(メッセージを閉じると再試行します)。画面はわずかに薄暗くなり(アラートの準備として)、警告は表示されません。UIAlertに何らかの遅延が必要ですか?
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;
}
目標に達する方法はありますか(問題が解決するまでこの方法でユーザーに警告する - 私はDRYに違反しない)? 複数の[警告表示](ユーザーに警告された場合に追加されたテスト)を回避するためにコードを再配置しましたが、サイコロはありません。 – BankStrong
はい、pUIAlertView]はWindowsのMsgBoxと似ていません。現在のイベントハンドラを終了する必要があり、ユーザがオプションを選択したときにコールバックメソッドが呼び出されます。 – U62