Note that there are some explanatory texts on larger screens.

plurals
  1. POUIActivityIndicator inside custom UICollectionViewCell - only displays/animate in first cell
    primarykey
    data
    text
    <p>I'm animating an ActivityIndicator after a user presses a button in my collection cell, while I wait on a network response. The code below is called by every instance of the custom cell (confirmed in debugger), but the activity indicator only displays when a button is clicked in the first cell, or when clicked in a cell reusing the first cell. It doesn't matter if I click the buttons in another cell before the first. </p> <pre><code>customCollectionViewCell.m @interface customCollectionViewCell(){ UIActivityIndicatorView *activityIndicator; } @implementation cutomCollectionViewCell - (void) choiceClicked:(id)sender{ dispatch_async(dispatch_get_main_queue(), ^{ activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; actvityIndicator.center = self.center; [self.contentView addSubview:activityIndicator]; [actvityIndicator startAnimating]; }); async - network stuff } </code></pre> <p>I'm making sure in prepare for reuse that I'm removing the indicator from superview and setting to nil. </p> <p>I've also tried only creating the indicator if it doesn't exist and starting animation - still no change in behavior.<br> edit: Also doesn't matter if just the animating is called from main thread and other calls are explicitly part of the default queue.</p> <pre><code>if (activityIndicator == nil){ activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; activityIndicator.center = self.center; [self.contentView addSubview:activityIndicator]; } dispatch_async(dispatch_get_main_queue(), ^{ [activityIndicator startAnimating]; }); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ network call }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload