Detect real end of the for () loop in objective-c

后端 未结 3 1328
不知归路
不知归路 2021-01-27 09:16

I\'m going to show in my app a sort of UIActivityIndicatorView while parsing several JSON objects, inside a for () loop. I can\'t figure WHERE I must place the [UIActivityIndica

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-27 09:46

    Your problem is that the requests you are making in your loop are asynchronous, so your loop doesn't hang around for them to complete, it just fires off each one in quick succession and your block of code to load your arrays is executed once the data is received.

    You could use a counter in your block that gets incremented every time a block finishes and then once the counter matches your [arrayJSON count] you know when to stop the animation. Just remember to use __block storage

    http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/Blocks/Articles/bxVariables.html

提交回复
热议问题