My app looks like this:
I have a UIScrollView and there is imageview inside. I implemented the scrollViewDidScroll delegate so that if th开发者_JAVA百科e scroll did scroll, I will create a NSURLConnection and download a data from some url, for only once.
The problem is that the NSURLConnection connectionDidFinishLoading only be called or run after I release my finger on the scroll view.
To be more clearly, If I use my finger to scroll the scrollview, I confirm that the NSURLConnection is created, but as long as I do not release the scrollview, the connectionDidFinishLoading is never called. Once I release my finger, the delegate of connectionDidFinishLoading is called.
Anyone can explain this to me please?
Thanks
That's because during scrolling the UI enters a modal loop processing the user scroll inputs, and until scrolling finishes your thread won't get back to the message queue to pick up any delegate messages from the NSURLConnection.
You could run the NSURLConnection in a separate thread, which should keep pumping messages when the user is scrolling, but you'd still not be able to call across to the UI thread. The way round that might be to have the connection thread write the data into a lock-free data structure that the UI thread can then read - but this is likely to be complicated!
精彩评论