Write a program used in the waterfall flow show way, but found that when the number of pictures is too large, in the iPhone4 will not smooth, this is very uncomfortable.
Writing code at the beginning is done some optimization, such as cell reuse, asynchronous loading, but still very card.
Finally found the crux of the problem, that is, if the slide too fast, it may be issued at the same time, such as 10 picture requests. Although these requests are running in the background, they may return to the UI thread at the same point in time. This time if loading pictures to uiimageview too often, it will cause the UI card serious. (although not visible on new ipad and iphone4s)
When this problem is found, the Performselectorafterdelay method is also found to accumulate when the UI thread is idle. The Dispatch_after or Dispatch_async will be inserted directly into the UI thread to execute on the spot. So this problem can actually be solved with performselectorafterdelay, the test is also very smooth, do not feel a little bit of card. But there is a new problem, that is, during the sliding process, no pictures are loaded. The picture will come out when you know ScrollView is stopped. Of course, this is not the ideal solution. This method also does not resolve the problem of reaching the UI thread in the asynchronous process set. The nsoperationqueue was then used to solve the problem.
The problem itself and the uitableview load is not smooth is the same.
Solutions
Mainly to do a few things:
- In addition to the UI section, all loading operations are done in the background.
This can be achieved by dispatch or Performselectorinbackground or nsoperationqueue. See:
Multithreaded programming with GCD in iOS development
Multi-threaded operation with Nsoperationqueue in iOS development
- Avoid background loading when multiple resources are completed and the processing time to occupy the UI thread is too long.
This can be accomplished through nsoperationqueue, where the presentation of the resource to the UI is executed one at a queue, and a forced wait after each operation is completed, which can be resolved with usleep (int microseconds).
- Reuse cell.
Creating a cell is generally slow, must be reused, and even for performance, you can create enough cells to reuse the queue at the beginning of view creation.
IOS TableView (Waterfall stream) when you swipe to fix