Permalink
Browse files

TTImageView Delegate improvement:

- Give the user the possibility to configure the Requester before TTImageView make the call to the server.
  • Loading branch information...
1 parent e2b7d54 commit efcf5e5e9e6695cda4f725929a75ae56f9c1f5e6 Paulo Oliveira committed Jun 22, 2011
@@ -77,6 +77,11 @@
@property (nonatomic, assign) id<TTImageViewDelegate> delegate;
/**
+ * The TTURLRequest requester used to load this image.
+ */
+@property (nonatomic, readonly) TTURLRequest* request;
+
+/**
* Cancel any pending request, remove the image, and redraw the view.
*/
- (void)unsetImage;
@@ -38,4 +38,11 @@
*/
- (void)imageView:(TTImageView*)imageView didFailLoadWithError:(NSError*)error;
+/**
+ * Called before the image view send a network request.
+ * At this point we have the opportunity to configure the requester
+ * with some custom options (to use ETAGs, for example).
+ */
+- (void)imageView:(TTImageView*)imageView willSendARequest:(TTURLRequest*)requester;
+
@end
@@ -44,6 +44,7 @@ @implementation TTImageView
@synthesize image = _image;
@synthesize defaultImage = _defaultImage;
@synthesize autoresizesToImage = _autoresizesToImage;
+@synthesize request = _request;
@synthesize delegate = _delegate;
@@ -208,6 +209,11 @@ - (void)reload {
TTURLRequest* request = [TTURLRequest requestWithURL:_urlPath delegate:self];
request.response = [[[TTURLImageResponse alloc] init] autorelease];
+ // Give the delegate one chance to configure the requester.
+ if ([_delegate respondsToSelector:@selector(imageView:willSendARequest:)]) {
+ [_delegate imageView:self willSendARequest:request];
+ }
+
if (![request send]) {
// Put the default image in place while waiting for the request to load
if (_defaultImage && nil == self.image) {

0 comments on commit efcf5e5

Please sign in to comment.