2010-09-20 28 views
1

如何調用主線程???我可以分析,但我不能顯示數據xml解析消耗時間需要iphone上的高效方式

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

您可以

  • viewDidAppear:嘗試,你去一個新視圖後,該方法被調用。那麼至少,你可以切換到新的視圖,你應該確保有東西在屏幕上等待XML解析

  • 使用線程:你把解析到另一個線程,然後後回叫你的主線程完成,那麼將不會有任何阻擋

+0

第二個線程。這就是我在處理SOAP Web服務調用時所做的,無需掛起顯示,直到調用從服務器返回爲止。 – drekka 2010-09-20 03:10:26

+0

是的,通常線程是一個很好的方法。 – vodkhang 2010-09-20 03:23:44

+0

嘿如何調用主線程只是看到我上面的代碼 – prajakta 2010-09-20 03:30:29