代码从后台线程返回后不工作



我有一个tableview(文件名- 5)。M)它工作得很好,并在表视图中正确显示数据。当用户选择一行时,它会在同一屏幕上添加一个显示Progress Indicator的子视图。添加子视图后,它启动一个后台线程,解析HTML数据并将其添加到SQLite3数据库。后台线程,SQLIte数据插入,HTML解析都工作良好。现在,当它结束时,它又回到5。在removeProgressInd方法中删除进度指示器并导航到新表视图(文件名- TitleOnly.m)。它成功返回,因为我可以看到来自removeProgressInd方法的所有NSLog消息。但代码不会停止进度指示器也不会移动到新表视图。代码运行无任何错误。我试图在viewDidLoad和viewDidAppear中运行相同的代码,而不是removeProgressInd,但我只看到NSLog消息。这是我的代码。

5。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 (appDelegate4.globalParsingCompletedFlag==@"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];
}

5。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];

}

我可以在控制台看到"navigate to TitleOnly"消息没有任何错误,这意味着它运行了[progressInd stopAnimating]和[self]。progressInd removeFromSuperview]命令成功执行,没有任何错误,因为这些命令就在此NSLog消息之前。但它不会从屏幕上移除进度指示器。类似地,它不会显示TitleOnly tableview。"

我该如何修复它?问题在哪里?我做错了什么?

请尽快回复

您是否尝试过使用断点和调试器来逐步解决问题?与使用NSLog()相比,您将了解更多关于这种方式发生的事情。

最新更新