开发者

How to show load bar in ipad app while data is fetching from xml after default png is shown

I am fetching XML data from server i want that when data is loading in progress i show a loading bar with default screen this is code in appDidFinishing

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    RootViewController * rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];    
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];  
    [self.window addSubview:navigationController.view];  


    self.activityIndicator =  [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(55, 67, 100, 100)];    

    [self.activityIndicator startAnimating];  
    [self.window addSubview:self.activityIndicator];  
    [self loadXMlTwo];
    [self loadXMlMain];
    [self performSelectorInBackground:@selector(loadXMlOne) withObject:nil];  

    [self.activityIndicator removeFromSuperview];



    [window makeKeyAndVisible];

    return YES;

}

-(void)loadXMlMain{

NSURL*url= [[NSURL alloc]initWithString:@"http://46.137.28.14/app/ipadApplic/working.xml"];



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

//Initialize the delegate.

XMLParser *parser = [[XMLParser alloc] initXMLParser];

//Set delegate

[xmlParser setDelegate:parser];         
BOOL success = [xmlParser parse];

if(success)

    NSLog(@"No Errors");

else

    NSLog(@"Error Error Error!!!");

} -(void)loadXMlOne{

NSURL*url1=[[NSURL alloc] initWithString:@"http://46.137.28.14/app/ipadApplic/rowone.xml"];






NSXMLParser *xmlParserRow = [[NSXMLParser alloc] in开发者_运维百科itWithContentsOfURL:url1];

//Initialize the delegate.

RowOneParser *parser1 = [[RowOneParser alloc] initXMLParser];   
//Set delegate

[xmlParserRow setDelegate:parser1];         
BOOL success1 = [xmlParserRow parse];

if(success1)

    NSLog(@"No Errors");

else

    NSLog(@"Error Error Error!!!");

} -(void)loadXMlTwo{ NSURL*urlRowTwo=[[NSURL alloc] initWithString:@"http://46.137.28.14/app/ipadApplic/rowtwo.xml"]; NSXMLParser *xmlParserRowTwo = [[NSXMLParser alloc] initWithContentsOfURL:urlRowTwo];

//Initialize the delegate.

RowTwoParser *parserRowTwo = [[RowTwoParser alloc] initXMLParser];

//Set delegate

[xmlParserRowTwo setDelegate:parserRowTwo];         
BOOL successRow = [xmlParserRowTwo parse];

if(successRow)

    NSLog(@"No Errors");

else

    NSLog(@"Error Error Error!!!");

}


What you need to do is unblock your main thread while you are doing background fetch of xml data. Easiest way to do that is add your fetch operations in NSOperationQueue. Set up delegates for the class which fetches the xml and handle the response.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜