2012-03-02 25 views
0

我已經爲didSelectRowAtIndexPath這個代碼,但我想優化代碼,使一個新的線程,推動視圖控制器從我的數據從JSON解析器。didSelectRowAtIndexPath調用新的線程

#pragma mark - DidselectRow 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    //SPINNER 
    [spinner startAnimating]; 


    //[self performSelector:@selector(pushDetailView:) withObject:tableView afterDelay:0.1]; 

    /* 
    int *riga = indexPath.row; 
    [NSThread detachNewThreadSelector:@selector(pushDetailView) toTarget:self withObject:riga]; 
    */ 

    NSLog(@"Seleziono l'immagine: %@", [photoTitles objectAtIndex:indexPath.row]); 

    //creo un'istanza di DettaglioView 
    DettaglioView *dettaglioImmagine = [[DettaglioView alloc] initWithNibName:@"DettaglioView" bundle:nil]; 



    //Inseirsco il titolo nella Navigation BAR della vista 
    dettaglioImmagine.titoloSource = [photoTitles objectAtIndex:indexPath.row]; 

    dettaglioImmagine.imageCoverSource = [photoURLsLargeImage objectAtIndex:indexPath.row]; 
    NSLog(@"imageCoverSource: %@", dettaglioImmagine.imageCoverSource); 


    //passo alla vista del DettaglioView con l'animazione usando il pushViewController 
    [self.navigationController pushViewController:dettaglioImmagine animated:YES]; 


    //pulisco lo style della cella selezionata togliendo il fondino blu 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    //Attivo la vibrazione 
    [self buzz]; 
} 

現在,我想做出推從didSelectRowAtIndexPath方法的外部方法類似這樣的細節視圖:

- (void)pushDetailView:(NSInteger *)idRow { 

    // Push the detail view here 
} 

現在我的問題是,如何才能通過indexPath。行方法pushDetailView?

我已經嘗試這一點,但它不工作

int *riga = indexPath.row; 
[NSThread detachNewThreadSelector:@selector(pushDetailView) toTarget:self withObject:riga]; 

回答

0

任何用戶界面的任務絕對必須在主線程上運行。這不是一個選項,背景UI操作可以並且會引發異常。在主線程上推新viewController之前,您必須在後臺加載數據。

+0

嗯但我有一個問題,我的「Spinne」是一個UIActivityIndi​​cator。 – WalterFantauzzi 2012-03-02 08:40:00

+0

嗯,我有一個問題需要解決,因爲我的微調是一個UIActivityIndi​​cator,當用戶點擊我的UITableview中的單元格時無法啓動。 我已經在我的init中定義了這個activityIndi​​cator spinner = [[UIActivityIndi​​catorView alloc] initWithActivityIndi​​catorStyle:UIActivityIndi​​catorViewStyleWhiteLarge]; UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:spinner]; [self navigationItem] .rightBarButtonItem = barButton; – WalterFantauzzi 2012-03-02 08:42:56

0

你不能傳遞int。而不是int - > nsnumber或nsstring可以保留

相關問題