2012-03-26 2 views
0

Ich frage mich, wie ich einen Aktivitätsindikator für eine Zelle von der didselectCellFromIndexPath-Methode anzeigen könnte?Aktivitätsindikatoranimation von Zellenauswahl

Grundsätzlich möchte ich den Aktivitätsindikator Animation aus der did select starten, sobald ich eine Rückgabe von meiner Parsing-Klasse bekomme ich würde die Animation stoppen und durch ein Häkchen ersetzen. aber ich bin mir nicht sicher, wie man das innerhalb der Didselecell Methode macht? Das ist der Code, den ich verwenden würde.

cellActivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
     [cell setAccessoryView:cellActivityIndicator]; 
//then 
[cellActivityIndicator startAnimating]; 
//then 
[cellActivityIndicator stopAnimating]; 

aber ich brauche nur ein paar Ratschläge es in indexPath auf tun: DidSelectRowAtIndexPath: Methode

Antwort

2

In Ihrem didSelectRowAtIndexPath Methode können Sie die Zelle zugreifen selbst mit:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

    //Initialise, add to cell's view and start your activity indicator 

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 

     //Call your function or whatever work that needs to be done 
     //Code in this part is run on a background thread 

     dispatch_async(dispatch_get_main_queue(), ^(void) { 
      //Stop your activity indicator 
      //Code here is run on the main thread 
     }); 
    }); 
} 

Diese Die Methode verwendet libdispatch/Grand Central Dispatch und erfordert iOS 4 oder höher.

+0

Danke das hat perfekt funktioniert. –

+0

Kein Problem Kumpel – sooper

+0

Das endete eine zweitägige Suche und viel Versuch und Irrtum - danke! – resedasue

2
dispatch_queue_t queue = dispatch_queue_create("Downloading image", NULL); 

dispatch_async(queue, ^{ 
    NSURL *url = [NSURL URLWithString:@"http://store.storeimages.cdn-apple.com/2441/as-images.apple.com/is/image/AppleInc/step0-edu-pricing?wid=264&hei=144&fmt=png-alpha&qlt=95"]; 

    cellActivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
    [cell setAccessoryView:cellActivityIndicator]; 

    NSData *downloadedImage = download data; 

    // update your UI screen 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [subViewActivityIndicator removeFromSuperview]; 
     [cell setAccessoryView:something]; 
    }); 
}); 
dispatch_release(queue); 
Verwandte Themen