I’m using UIImageView+AFNetworking:setImageWithURLRequest to load images into table view cells. It’s working great and I tried using AFNetworkActivityIndicatorManager as in the example below to display the activity indicator while the images are loading.
[[AFNetworkActivityIndicatorManager sharedManager] incrementActivityCount];
[imageView setImageWithURLRequest:request placeholderImage:[UIImage imageNamed:placeholder]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
[[AFNetworkActivityIndicatorManager sharedManager] decrementActivityCount];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
[[AFNetworkActivityIndicatorManager sharedManager] decrementActivityCount];
}
];
The problem I’ve run into is when scrolling quickly through the table view AFNetworking cancels certain requests and the AFNetworkActivityIndicatorManager never gets decremented. Canceling requests does keep things fast and appears to be by design:
“As table view cells are recycled, for instance, setting a new image URL will automatically cancel the previous request.” https://github.com/AFNetworking/AFNetworking/wiki/Introduction-to-AFNetworking
Is there a way to detect the cancellation so I can decrement the AFNetworkActivityIndicatorManager or is there a better way to make sure the requests and activity indicator stay in sync?
Thanks!
You shouldn’t need to do this all you need to do is call:
in you AppDelegate application:didFinishLaunchingWithOptions: and then AFNetworking looks after hiding and showing the indicator as and when network connections start and stop.