ios - UICollectionView select cell at indexPath while reloading -
I have a collection view to show photos from the server.
The download is slow on the server and I want to show the newly downloaded photo Every time this code to
in CollectionView I reload, while the photo download
for (int x = 0; x & LT; thumbsLink. Count; x ++). {NSData * Data = [NSData DatyWid content of URL: [NSDR URLWithString: [Ring Objects Object: X]]]; UIImage * image = [UIImage imageWith data: data]; Dispatch_assink (dispatch_gate_man_quoo ()), ^ {[thumb-piece object: image]; [Self-dependable reload data];}); }
It works well, but I can not select the cell for the row on the index path until the downloading is complete.
How can I select a cell before downloading to see downloaded downloads?
After
Because you have worked on main thread instead of async threads.
You should change your code to:
class offslack * __wec weaklels = self; For (int x = 0; x & LT; thumbsLink.count; x ++) {dispatch_async (dispatch_get_main_queue (), ^ {NSData * data = [NSData dataWithContentsOfURL: [NSURL URLWithString: [thumbsLink objectAtIndex: x]]]; UIImage * image = [UIImage imageWithData: data]; [thumbs addObject: image]; [[recovers self-view view]; reload data;}); }
You also need to use weak
to reference the reference for yourself for a strong reference cycle.
You can also do this in a concurrent enumeration block:
Clasofslef * __vek Kmjorslf = self; [ThumbsLink enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^ (id obj, NSUInteger IDX, BOOL * off) {NSData * data = [NSData dataWithContentsOfURL: [NSURL URLWithString: obj]]; UIImage * image = [UIImage imageWith data: data]; [Thumb addObject: image]; [[View weak self-view] reload data]; }];
Apple's documentation:
The enumeration block code processor intensive and secure concurrent, execution, you can use NSEnumerationConcurrent options :
this flag indicates that Gnn block invocations can be distributed across multiple threads, offering a growth potential exposure if the block code is particularly processor intensive note that Gnn order option Is undefined while using.
Comments
Post a Comment