2013-04-08 119 views
3

當我點擊表格視圖單元格時,它將在同一個表格視圖中持續一段時間(直到下一頁完全加載),那麼它將顯示下一個視圖..當點擊表格視圖單元格時緩慢加載

我要上單擊表格視圖單元格,應立即後藤下一個頁面,並顯示加載頁面彈出..

我有impActivityAgent嘗試,並試圖表明警報視圖時,它會進入下一個頁面(但查看是前一頁即表格視圖)..但..其完全加載頁面,這將需要時間,然後其顯示警報..

在下一頁我發佈和解析數據,這將需要時間,在那段時間我想顯示活動指標..

我已經嘗試了很多方法,但仍然第一次完全加載下一頁,然後顯示內容或alertView或活動的指標,我不能夠在表格視圖單元格單擊時,顯示活動的指標..

我的代碼:

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

或下一視圖控制器是:

- (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]; 
} 

和在解析函數我解析我得到的內容,作爲HTML格式的答覆使用「hpple」解析器..

+0

檢查任何回地面的過程是怎麼回事代替ü選擇的行之後。發佈一些相關的代碼。 – Ganapathy 2013-04-08 04:33:55

+0

no there is no back groung正在進行的過程.. – Raju 2013-04-08 04:39:22

+0

@Raju,發佈您的代碼 – 2013-04-08 04:40:24

回答

2

只需使用一個單獨的線程來處理解析。希望這段代碼能幫助你。

- (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 ur table view name 

} 
+0

現在得到我所需要的但它不調用「 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath」函數..它存在於nextViewController .. – Raju 2013-04-08 05:31:47

+0

現在檢查。更新了我的答案。一旦解析完成,U需要重新加載表視圖。 – Ganapathy 2013-04-08 05:36:17

+0

雅感謝它的工作.. – Raju 2013-04-08 05:39:37

1

試試這個

-(void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
    [[ImpActivityAgent defaultAgent] makeBusy:YES]; 
    [self performSelectorInBackground:@selector(start) withObject:Nil]; 
    //or you can use after delay then no need to use perform selector on main thread in start method. 
    [self performSelector:@selector(start) withObject:nil afterDelay:0.5]; 
} 

-(void)start 
{ 
    NSURL *loadUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/gmail.com",inputURL]]; 
    htmlData = [NSData dataWithContentsOfURL:loadUrl]; 
    self.htmlSTR = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding]; 
    [self performSelectorOnMainThread:@selector(parseHTML) withObject:Nil waitUntilDone:YES]; 
} 
0

試試吧....

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(newMethodForParsing) userInfo:nil repeats:NO]; 
} 

-(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]; 
} 
+0

@Raju:嘗試我的代碼它是100%幫助你我多次使用它.... – 2013-04-08 05:28:52

+0

對不起,它不工作.. – Raju 2013-04-08 12:06:18

0

Ganapathy的回答是存在內存泄漏,你需要放置一個autoreleasepool的方法內。這是一個更簡單的方法來做到這一點。這將在主線程上運行,但在隊列中的現有任務之後運行。

如果你想讓它在不同的線程運行與dispatch_get_global_queue()

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

    dispatch_async(dispatch_get_main_queue(), ^{ 

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