プライベートMBProgressHUDを使用しています
現在、addrecordサービスを呼び出している追加ボタンのインジケータービューを使用しています。
UIWindow *window = [UIApplication sharedApplication].keyWindow;
HUD = [[MBProgressHUD alloc] initWithWindow:window];
// Add HUD to screen
[window addSubview:HUD];
// Regisete for HUD callbacks so we can remove it from the window at the right time
HUD.delegate = self;
// Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:@selector(addingToFavorites) onTarget:self withObject:nil animated:YES];
お気に入りに追加する方法:
NSURL *url = [NSURL URLWithString:urlstring];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
//[request setTimeoutInterval:10];
//NSURLResponse *response = nil;
// NSError *error = nil;
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
NSData *data1= [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
if(data1 == nil)
{
doneFlag = NO;
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alert"
message:@"The network is not available.\n Please check the Internet connection."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
doneFlag = YES;
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Confirmation"
message:@"Added To favorites"
delegate:nil
cancelButtonTitle:@"OKAY"
otherButtonTitles:nil];
[alert show];
alert = nil;
[alert release];
}
[request release];
楽器がuialertviewのリークを与えることを除いて、これはすべて正常に実行されています。これは、mbprogreshudと競合している可能性があります。
そこで、呼び出し元のメソッドからアラートを削除して、呼び出し元に次のようなメソッドを配置することを考えました。
呼び出し元のメソッドは次のようになります。
UIWindow *window = [UIApplication sharedApplication].keyWindow;
HUD = [[MBProgressHUD alloc] initWithWindow:window];
// Add HUD to screen
[window addSubview:HUD];
// Regisete for HUD callbacks so we can remove it from the window at the right time
HUD.delegate = self;
// Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:@selector(addingToFavorites) onTarget:self withObject:nil animated:YES];
//it should wait for the above line to be executing ******* then to exexute the be //below condition but how ?
if (doneFlag == NO) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alert"
message:@"The network is not available.\n Please check the Internet connection."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
} else {
[favoritesButton setTitle:@"Remove" forState:UIControlStateNormal];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Confirmation"
message:@"Added To favorites"
delegate:nil
cancelButtonTitle:@"OKAY"
otherButtonTitles:nil];
[alert show];
alert = nil;
[alert release];
}
お気に入りに追加する方法:
NSURL *url = [NSURL URLWithString:urlstring];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];
//[request setTimeoutInterval:10];
//NSURLResponse *response = nil;
// NSError *error = nil;
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
NSData *data1= [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
if(data1 == nil)
{
doneFlag = NO;
}
else
{
doneFlag = YES;
}
[request release];
progresshudスレッドの起動では、次のようなものが切り離されています。
[NSThread detachNewThreadSelector:@selector(launchExecution) toTarget:self withObject:nil]
今私の質問は、私が最初のシナリオに従う場合です。アラートビューのリークが発生しないことをどのように保証できますか
または、2番目のシナリオに従っている場合、この行の実行が完了した後にif条件が実行されることをどのように保証できますか?
[HUD showWhileExecuting:@selector(addingToFavorites) onTarget:self withObject:nil animated:YES];