我有一個tableview(文件名-5.m),它工作正常,並正確顯示tableview中的數據。當用戶選擇一行時,它會在同一屏幕上添加一個顯示進度指示器的子視圖。添加子視圖後,它啓動一個後臺線程,解析HTML數據並將其添加到SQLite3數據庫。後臺線程,SQLIte數據插入,HTML解析都工作正常。現在,當它完成時,它會在removeProgressInd方法中返回到five.m,該方法將刪除進度指示器並導航到新的表視圖(文件名TitleOnly.m)。它可以成功返回,因爲我可以看到來自removeProgressInd方法的所有NSLog消息。但是代碼不會停止進度指標,也不會移動到新的tableview。代碼運行沒有任何錯誤。我試圖在viewDidLoad和viewDidAppear中運行相同的代碼,而不是removeProgressInd,但我只看到NSLog消息。這是我的代碼。從後臺線程返回代碼不工作
Five.m - 的tableview DidSelelectRow
{
// start ProgressInd
[self.view addSubview:self.progressInd];
// shows progress Indicator on screen when I run my app in simulator
// start Parsing Calculation in Background thread
if ([email protected]"0")
{
NSLog(@"starting backgroung thread- parsing calulation- because flag==0");
ParsingCalculation *parsC = [[ParsingCalculation alloc] init];
[queue addOperation:parsC];
[parsC performSelectorInBackground:@selector(main) withObject:nil];
[parsC release];
//successfully starts parsing in background
}
}
ParsingCalculation.m文件代碼
- (void)main {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
//your code to do the operations...
appDelegate5=[[[UIApplication sharedApplication] delegate] retain];
NSLog(@"Now we are in ParsingCalulation.m");
//resultsFromURL is another method in parsingCalulation.m that does all parsing successfully
[self resultsFromURL:appDelegate5.globalLocationURL];
NSLog(@"Now we are moving back in Five.m -calling function removeProgressInd ");
[[Five shared] performSelectorOnMainThread:@selector(removeProgressInd)
withObject:nil
waitUntilDone:YES];
//it returns back to five.m successfully after finishing HTML Parsing
[pool release];
}
Five.m - removeProgressInd方法
-(void) removeProgressInd{
NSLog(@"Now we are back in Five.m -in function removeProgressInd ");
//remove progressInd from superview as parsing calculation has been completed
[progressInd stopAnimating];
[self.progressInd removeFromSuperview];
//move to TitleOnly.m tableview
NSLog(@"navigate to TitleOnly ");
TitleOnly *newView = [[TitleOnly alloc] initWithNibName:@"TitleOnly" bundle:nil];
[self.navigationController pushViewController:newView animated:YES];
[newView release];
}
我可以在控制檯中看到「導航到TitleOnly」消息而沒有任何錯誤,這意味着它成功運行了[progressInd stopAnimating]和[self.progressInd removeFromSuperview]命令,沒有任何錯誤,因爲這些命令就在此NSLog消息之前。但它不會從屏幕上刪除進度指標。同樣,它不顯示TitleOnly tableview。 ''
我該如何解決它?哪裏有問題?我究竟做錯了什麼?
請儘快回覆。