I'm using
[assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:failureBlock];
to enumerate Photo Albums.
The enumerator is acting in an "asynchronous" way, in other words the methods returns before enumerating all items.
开发者_Python百科How can I know when the enumeration is finished?
I'm populating a NSMutableArray with the groups, and would to call [myTableView reloadData]
after enumeration is finished.
Your enumeration will give your block a nil-pointer group and set stop to true when it goes through its last pass. You can use this to set a flag or call some finishing code using performSelectorOnMainThread: on the next pass through the RunLoop.
I looked at the API for this, because I thought at first that the answer would be to use some synchronous method to do the same thing. Since there isn't such a method, I suspect that due to some implementation detail the enumerator doesn't know ahead of time how many items it has. Plus, it may be slow.
In that case, I would reload the table while the enumeration is running, being very careful not to block either the main thread or enumeration thread. Here's what I would try:
Do the enumeration, storing new items in an array for displaying in the table. Every X seconds (0.1 maybe?), add the new items to an array used as a data source for the the table, and then reload it. Be sure to use performSelectorOnMainThread: when adding to the table's array or reloading its data. Once you have added those items to the table's array, a new array of items that will be added to the table array.
This approach will have the benefit to the user that the table will immediately begin loading, even if it actually takes a while to load everything.
精彩评论