tags:

views:

40

answers:

1

How to call main thread ??? i can parse but i cant display data

- (void)viewDidLoad {
    //self.navigationItem.rightBarButtonItem = self.editButtonItem;
    self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"10.png"]];
    [super viewDidLoad];
  [NSThread detachNewThreadSelector:@selector(startTheBackgroundJob) toTarget:self withObject:nil]; 

      }


- (void)startTheBackgroundJob {  


    NSUserDefaults *getida = [NSUserDefaults standardUserDefaults];

        myIDa = [getida stringForKey:@"AppID"];

        NSLog(@"@BOOK MARK ");



        NSString *ubook = [[NSString alloc] initWithFormat:@"http://www.wapp=%@&action=show",myIDa];
        NSLog(@" bookmark %@",ubook);
        [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
        //NSString *outputString = [[NSString stringWithString:usearch] stringByAppendingString: UserText];
        ubook = [ubook stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];


        NSLog(@"My string is  now =  %@", ubook);

        NSURL *url = [[[NSURL alloc] initWithString:ubook]autorelease];
        //NSURL *url=   [NSURL URLWithString:outputString];

            NSLog(@" bookmark URL IS  %@",url);

        NSXMLParser *xmlParser = [[[NSXMLParser alloc] initWithContentsOfURL:url] autorelease];

        //Initialize the delegate.
        XMLParserbookm *parser = [[[XMLParserbookm alloc] initXMLParser]autorelease];

        //Set delegate
        [xmlParser setDelegate:parser];

        //Start parsing the XML file.
        BOOL success = [xmlParser parse];
        if(success)
        {

            NSLog(@" xml parsed suucess");

            //[super viewDidLoad];

            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;


            //[self searchTableView];   
            //mytimer4=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(wipe) userInfo:nil repeats:NO];
        }

        else{
            NSLog(@"eeror");
        }
        [NSThread sleepForTimeInterval:3];  
    [self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil  waitUntilDone:NO];   // HOW TO CALL MAIN THREAD
    [pool release]

}
+1  A: 

You can try with

  • viewDidAppear:, this method is called after you go to a new view. Then at least, you can switch to new view, you should make sure that there is something on the screen in waiting for the xml parsing

  • Using Thread: You put parsing into another thread and then callback your main thread after you finish, then there will be no block at all

vodkhang
Second the threading. That's what I do for processing SOAP web service calls without hanging the display until the call comes back from the server.
Derek Clarkson
yeah, usually thread is a good way to do.
vodkhang
hey how to call main thread just see my updated code above
prajakta
` // [self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO]; // HOW TO CALL MAIN THREAD` This line is correct, what is wrong with that? Do you have a method call makeMyProgressBarMoving?
vodkhang
yes i did and i just added -(void)makeMyProgressBarMoving { [tableview reloaddata]} so its working now but i dont know whether this process is right or wrong anyway Thanks a lot
prajakta