开发者

Code not working after returning back from background thread

开发者 https://www.devze.com 2023-03-26 14:41 出处:网络
I have a tableview (file name- five.m ) which works fine and shows data in tableview properly. When a user select a row then it adds a subview which shows a Progress Indicator on the same screen. Afte

I have a tableview (file name- five.m ) which works fine and shows data in tableview properly. When a user select a row then it adds a subview which shows a Progress Indicator on the same screen. After adding subview it starts a background thread which parse HTML Data and add it to SQLite3 database. Background thread, SQLIte data insertion, HTML Parsing all are working fine. Now when it finishes then it returns back to five.m in removeProgressInd method which removes progress indicator and navigate to new table view (file name- TitleOnly.m). It returns successfully as I can see all NSLog messages from removeProgressInd method. But code doesn't stop progress Indicator and doesn't move to new tableview. Code runs without any error. I tried to run the same code in viewDidLoad and viewDidAppear instead of removeProgressInd but I see only NSLog Messages. Here is my code.

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 (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 file code

- (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 method

-(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];


}

I can see "navigate to TitleOnly" message in console without any error it means it ran [progre开发者_StackOverflowssInd stopAnimating] and [self.progressInd removeFromSuperview] commands successfully without any error as these commands are just before this NSLog message. But it doesn't remove progress Indicator from screen. Similarly it doesn't show TitleOnly tableview. ''

How can I fix it? where is the problem? What am I doing wrong?

Please reply as soon as possible.


Have you tried using breakpoints and the debugger to step through the problem? You will learn much more about what is going on this way as opposed to using NSLog()'s.

0

精彩评论

暂无评论...
验证码 换一张
取 消