开发者

xml parsing consumes time need efficent way on iphone

How to call m开发者_StackOverflowain 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]

}


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜