The immediate problem, as rdelmar pointed out, is that you're not saving the NSURLConnection
references in the ivars that you refer to later. That's the first thing to fix.
The broader problem is more fundamental. You're starting three connections, but your connectionDidFinishLoading
seems to not recognize that fact it will get called three times, once for each connection. Notably the latter part of that routine, which is creating the map view and the segment control, will be performed once for each of the three JSON download requests. Surely you meant to do that UI-related stuff only once, when all three connections were done.
The elegant approach would be to wrap these individual network requests in NSOperation
objects and use operation queue to manage the "completion logic" which would include the UI stuff. You could implement this with AFNetworking, or wrap the NSURLConnection
in your own NSOperation
subclass. Then you could add these three operations, but have a final completion operation, dependent upon the completion of the other three download operations, which would update the UI.
A simpler fix to your existing code would be to add three boolean ivars, indicating whether the three individual downloads were done. Then your connectionDidFinishLoading
, as it's called each time for the three download requests, could update the respective boolean for each. And it would then only perform the UI related stuff if all three were done.