Search code examples
iphoneiosios5ios4ios6

slow loading when clicked on table view cell


When i click on table view cell, it will be in the same table view for some time(till the next page is completely load) then it will display the next view..

i want on click on the table view cell, it should immediately goto next page and show the loading page popup..

i have tried with impActivityAgent and also tried to show alert view when it will enter the next page(but view is of previous page ie table view).. but.. its loading the page completely, which will take time and then its showing alert..

in next page i am posting and parsing the data which will take time, during that time i want to show the activity indicator..

i have tried many methods, but still its first loading the next page completely and then displaying the contents or alertView or activity indicator and i am not able to show the activity indicator when clicked on table view cell..

MY CODE:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    nextTableViewController *doc = [[nextTableViewController alloc]initWithNibName:@"nextTableViewController" bundle:nil];
    [self.navigationController pushViewController:doc animated:YES];
}

AND NEXT VIEW CONTROLLER IS :

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[[ImpActivityAgent defaultAgent] makeBusy:YES];

NSURL *loadUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/gmail.com",inputURL]];
htmlData = [NSData dataWithContentsOfURL:loadUrl];
self.htmlSTR = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
[self parseHTML];
}

and in Parse function i am Parsing the content which i got as response in HTML formate using "hpple" Parser..


Solution

  • Just use one separate thread to handle parsing. Hope this code will help you.

    - (void)viewDidLoad
    {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [[ImpActivityAgent defaultAgent] makeBusy:YES];
    
    [NSThread detachNewThreadSelector:@selector(newMethodForParsing) toTarget:self withObject:nil];
    
    }
    
    
    -(void)newMethodForParsing
    {
    NSURL *loadUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/gmail.com",inputURL]];
    htmlData = [NSData dataWithContentsOfURL:loadUrl];
    self.htmlSTR = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
    [self parseHTML];
    
    [tableView reload]; // tableView refers to your table view name
    
    }