I'm developing on the iPhone and I have seen in the AppStore that the images are progressively downloaded in the UITableView... How can I implement that?
My idea was to detect the showed content (which cells are shown) and download these images. My problem is that I don't know how to detect the showed cells!
Is it the good way to do it?
Best
The way this was demonstrated at the iPhone Developer Tech Talk was to use NSOperation and NSOperationQueue.
The idea is to wrap up your image download request (using NSURLRequest) into an NSOperation.
You can set your cell as the receiver of a call back sent by your operation when it's complete so that you can attach the image to the cell (draw it manually, or add it to an image view).
Then basically, in your cellForRowAtIndexPath method, tell the cell to start the image download, and have the cell create an NSOperation and add it to the operation queue managed by your table view controller or something.
The queue will start executing the operations and call back to each cell when they're done.
If you want to, you can cancel the operation if the cell moves offscreen, so you don't waste resources downloading an image that will be thrown away because the cell won't be visible to display the image.
Here's an example of how to do this that implements the basic idea that Jasarien talks about. It may be sufficient depending on your application's needs and is generally good example of how to do it if it isn't.
I would implement each cell as a subclass of UITableViewCell and then override willMoveToWindow: method in the subclass. willMoveToWindow: is called when the cell view becomes visible on the screen or when it goes off screen (newWindow gets nil). Then each cell can queue a request to load its image as it becomes visible (and maybe even cancel its queued request if it goes off screen).
BTW, You can use the visibleCells property of UITableView to get the list of cells that are visible.
#Jasarien: nice answer
Or you can use the three20 project if you want. there is a TTTableViewController that already handles all the stuff you want. you only have to input the URL to the imageview and viola.
TT also caches your images in memory or also on disk.
check out the sample project bundled in three20 gitbub ressource. there an example.
That is calles LazyTableView...You can gt tutorial from here
http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html
Please go through this link , and try to integrate Lazy table view load , you can achieve you output , http://www.cocoaintheshell.com/2011/05/progressive-images-download-imageio/ change the url in ProgressiveImageDownloadViewController in Download button click method.
Related
When I scroll to new area of the UITableView with lazy image loading, then
immdietly scroll back to the old area, no matter what I do now, the new area will not show new images.
My code is based on apple lazy table view.
Till now I thought it was something with the web server, but I had cache functionality now, and all images are loaded from iphone files, so for sure there is somthing wrong in my code.
Again, the images are not shown ONLY in that case :
UITableView is loading the data
All visible cell are showing the images correctly.
If I scroll to new area, move to old area *quickly* and move back to new area the image will not load, no matter where I scroller now(only the images in the new area that I quickly scorll back from will not load)
all on other cases, the images are shown correctly.
Without seeing the some code its hard to say. If your display is tied to a callback from the NSURLConnection you might be losing your reference to the delegate.
When you scroll the cell view get repopulated with the data in the new cell. If the NSURLConnection is running outside of the cell view you might be losing the reference to it's delegate. When the NSURLConnection is completed if it doesn't have a delegate to fire the complete method then it won't get called. When you scroll to the new cell the NSURLConnection is already complete so it doesn't call the completed again and the spinner just keeps going.
I fix it. the bug was nothing to do with all above. so nothing to share and learn from.
I thought it is important for other I'll be clear about that, so no one will be confused about what I wrote earlier.
The process of checking if image already download was wrong.
I'm developing an application that get images from a website and display to user with a grid view like Photo app by Apple.
When you tap on an image I would to push a view controller that displays images info and other stuff.
What's the better way to implement this? I thought a custom UITableViewCell. (I've seen there are Three20 and AQGridView libs but I'm a newbie developer and the docs are very very poor. Hints?)
Thanks.
I think the UITableView is the best way of doing it. Its memory efficient and your only going to display 3 images anyway so the overhead isn't that bad. A tip, when your asynchronously getting images from the website, create a custom view is a delegate of NSURLRequest, get the data from a webpage, parse the data into a UIImage using imageWithData and when the finished delegate method is called, put a imageview on top of the custom view. This is the best method of downloading asynchronous methods. Good luck!
I made a thumbnail grid list like tableView but multicolumn, it's open source, on
http://www.cocoacontrols.com/platforms/ios/controls/thumbnail-list-view
https://github.com/mohammedDehairy/ThumbnailList
I have made an uitableView and I am fetching data from json from a webservice
now i want that I get first 20 object first and load it in my tableView. it is happening properly
Now I want that when user scroll to the footer ..next 20 data should be fetched and it should be shown in tableView..
I am stuck here ..can anyone give me any idea how to proceed next?
May be you can put Load more button in footerview and by tapping that you can load another 20 records from server ?
Another method is to implement Pull To Refresh and modify it as per your need.
You can use a ready made implementation of a UITableView with pull-to-refresh functionality.
Have a look at EGOTableViewPullRefresh or for a simpler implementation to PullToRefresh.
If you are interested in implementing this yourself, one approach is to add a subview to your UITableView (e.g., UILabel showing the "pull to refresh" message); then "intercept" the delegate methods when the user scrolls down (or up) and calculate whether the subview came into the viewable frame. Then issue the reload.
Another approach would be adding a last row to your table; then when the tableView:cellForRowAtIndexPath: method of your data source is called, return a cell with the "pull to refresh" message and do the refresh.
But you will be better off using one of the suggested implementations.
To know if you reached the button of the table (aka: seeing the footer) I think you could use this:
How to know when UITableView did scroll to bottom in iPhone
I'm having an issue where my UITableViewCell's image (I customized it into a cell with just the image) is not showing up after being downloaded unless you have scrolled down to make it invisible and scroll up to see again.
I am using HJCache for asynchronous image downloading as well as caching. What I am not sure is if this was the issue with HJCache or my UITableViewCell and how to fix it.
When the image has finished downloading (assuming the cell itself is the delegate for the asynchronous call), call [self setNeedsDisplay] which will redraw the cell. This is what happens when the cell is reloaded because of scrolling.
Well, I'm just going to answer my own question since I had found the most ridiculous solution.
After trying out various methods and headaches, I deleted the app ( + cache) from the simulator and everything seems to be working properly again.
My best guess is that the locally stored unfinished images by HJCache were messing up.
As soon as your data is finished loading, call [tableView reloadData]; This will make the tableView reload all of it's cells that are currently visible.
When you set up the cell set the image to nil. If that doesn't work set the image to a default locally stored image of the same size web if it's just completely white.
It's been more than 3 years since Cocoa-Touch is out, the licensing is permissive now.
Many, many apps have UIImageViews that are actually buttons, and load from the internet.
Is there any open UIImageView subclass (or similar) that supports:
adding a target for the touchUpInside event (maybe others too)
initializing with a NSURL, loading the image from that URL (async ofc) and displaying a UIProgressIndicatorView while loading
Or is everyone pretty much rolling their own for this?
It seems to be such a common thing, yet google has no good hits.
You wouldn't want the UIImageView derived class to load its image--especially if it's in a table view because when the user scrolls the table view, the image that will display in the image view would need to change. If you are assigning a specific image to a specific image view within a table view, you run the risk that the image displaying will be out of date by time the image data has actually returned.
While I wouldn't call it trivial as Daniel said, I would say that it is simple enough that you could probably code it up fairly quickly. The idea though is that you want to have some other class, a singleton perhaps, that handles all of your image download requests and then notifies your view that contains your image view that the images are available when the requests complete.
You should also consider that you can set an image for a UIButton, so then you wouldn't need to derive your own UIImageView if all you need is -touchUpInside. You could create an action for the button and implement it pretty easily.