I will try to narrate the problem in simple words. I am fairly new to programming for the iOS. I am developing an application which fetches a xml based response from server. The application consists of 4 tabs which trigger a different request and all the responses are xml based.
Problem Scenario:
Suppose i press the first tab it sends request for first set of data. In normal scenario i parse the response and display it on the screen. Screen is composed of a UIScrollView
and i add subviews to make it look like a grid view of images. I request for the images while creating the grid view. The url for the images are part of the response. Again this is a async request and update the grid vie开发者_如何学Gow based on the index. It works fine if i dont press any other tab during the whole update process. Suppose i press a different tab then it also triggers a request to server.
I am sending Async request for every fetch and storing the resposes in my data model which is basically a singleton. I can therefore access all the responses in my viewcontroller when i populate the views.
Problem arises when the first tab contents are being retrieved from server and a different tab is pressed. I want to stop the downloading of images/responses which were initiated from the first tab press. My model is capable of holding the data received including the images and trigger a new request for image in case it was not downloaded during the first time.
During this process the UI becomes totally unresponsive. I don't want to have a unresponsive UI.
- How do i efficiently do this without having to download contents twice also?
- Can there be a better approach to achieve this?
PS: I will paste the code if needed stripping of the unwanted details but it would be great help if you know what is a good way of sending the requests and handling them without making the UI unresponsive. Edit:
I create 100 subviews and add it to the scroll view. During this time i cant scroll and hence it gives a feeling of hanging. How do i update the UIscroll view without having to compromise in the responsiveness?
I'm writing an app that makes heavy use a web service to provide the data to display on screen. I do all downloading in an NSOperation that runs inside a NSOperationQueue of a singleton "data manager" class. The NSOperation does a "performSelectorOnMainThread" to the data manager singleton when the download is complete, the data manager stores the new data, and posts a NSNotification that it has new data available. Any UIViewController that cares about the data updates in that particular manager registers for that update notification.
With this structure, the app UI runs very smoothly, no hiccups or stalls.
Using the same sort of organization, it's very easy to create a "LazyUIImageView" class that downloads its image in an NSOperation (and could show an activity indicator while waiting for image download to complete). Tables with LazyUIImageView scroll smoothly, and when the image data finally arrive, the images just "pop" right in to view.
精彩评论