Cocoa-Touch: Is there any open-source UIImageView subclass that supports touchUpInside and initWithUrl?

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.

Answers


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.


Need Your Help

How do I do a switch case with saving in the same array?

php arrays

I need to save some numbers in my array. The numbers are the