2012-03-02 3 views
0

J'ai ce code pour didSelectRowAtIndexPath, mais je veux optimiser le code pour créer un nouveau thread qui pousse un contrôleur de vue avec mes données d'un analyseur JSON.didSelectRowAtIndexPath pour appeler un nouveau thread

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

Maintenant, je souhaite faire une méthode externe de didSelectRowAtIndexPath pour pousser la vue détaillée comme ceci:

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

    // Push the detail view here 
} 

Maintenant, mon problème est, comment puis-je passer le indexPath. méthode de ligne pour pousserDetailView?

J'ai essayer, mais ça ne marche pas

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

Répondre

0

Toutes les tâches d'interface utilisateur ABSOLUMENT MUST course sur fil conducteur. Ce n'est pas une option, la manipulation de l'interface utilisateur en arrière-plan peut provoquer une exception. Vous devez charger vos données en arrière-plan avant de pousser viewController sur le thread principal.

+0

Bien Mais j'ai un problème avec mon "Spinne" qui est un indicateur UIActivity. – WalterFantauzzi

+0

Eh bien, j'ai un problème à résoudre pour mon spinner qui est un UIActivityIndicator qui ne démarre pas lorsque l'utilisateur clique sur la cellule dans mon UITableview. J'ai défini dans mon init cette activitéIndicator spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge]; UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView: spinner]; [self navigationItem] .rightBarButtonItem = barButton; – WalterFantauzzi

0

Vous ne pouvez pas passer int. au lieu de int -> nsnumber ou nsstring qui peut être retenu

Questions connexes