Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed crash happening trying to access on dealloced delegate

Removed delegate support altogether. If we do need to use delegates, we'll figure out a proper solution.
  • Loading branch information...
commit e4e0621f3a0f2e911cb3f2edaf467985a172b005 1 parent 68f226f
@ettore authored
View
14 CLCGCell.m
@@ -11,9 +11,9 @@
#import "CLCGCell.h"
-#define GRCELL_IMG_DEFAULT_W 60.0f
-#define GRCELL_IMG_DEFAULT_H 60.0f
-#define MAX_CELL_H 20000.0f
+#define CLCGCELL_IMG_DEFAULT_W 60.0f
+#define CLCGCELL_IMG_DEFAULT_H 60.0f
+#define MAX_CELL_H 20000.0f
@implementation CLCGCell
@@ -38,8 +38,8 @@ -(void)dealloc
// overriding super-class designated initializer
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)cid
{
- return [self initWithImageWidth:GRCELL_IMG_DEFAULT_W
- height:GRCELL_IMG_DEFAULT_H
+ return [self initWithImageWidth:CLCGCELL_IMG_DEFAULT_W
+ height:CLCGCELL_IMG_DEFAULT_H
padding:0
reuseId:cid];
}
@@ -75,7 +75,7 @@ -(id)initWithImageWidth:(CGFloat)w
// know the width when we calc the cell height in the TV controller) let's
// provide a default size here, slightly bigger than actual to avoid
// calculating a cell height that's too small.
-#define GRCELL_ACCESSORY_DISCL_W 22.0
+#define CLCGCELL_ACCESSORY_DISCL_W 22.0
[self setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
return self;
@@ -177,7 +177,7 @@ +(CGFloat)textLabelWidthWithMax:(CGFloat)maxw
imageW:(CGFloat)imgw
padding:(CGFloat)pad
{
- return maxw - imgw - ((imgw > 0) ? pad:0) - pad*3 - GRCELL_ACCESSORY_DISCL_W;
+ return maxw - imgw - ((imgw > 0) ? pad:0) - pad*3 - CLCGCELL_ACCESSORY_DISCL_W;
}
View
4 CLCGImageLoader.h
@@ -31,10 +31,6 @@ typedef void (^CLCGImageLoaderCallback)(UIImage *img, int http_status);
+(ASIHTTPRequest*)loadImageForURL:(NSString*)normalurl
retinaURL:(NSString*)retinaurl
- delegate:(id<CLCGImageLoaderDelegate>)delegate;
-
-+(ASIHTTPRequest*)loadImageForURL:(NSString*)normalurl
- retinaURL:(NSString*)retinaurl
useCache:(BOOL)use_cache
block:(CLCGImageLoaderCallback)block;
View
56 CLCGImageLoader.m
@@ -50,35 +50,9 @@ +(CLCGImageLoader*)i
+(ASIHTTPRequest*)loadImageForURL:(NSString*)normalurl
retinaURL:(NSString*)retinaurl
- delegate:(id<CLCGImageLoaderDelegate>)delegate
-{
- return [CLCGImageLoader loadImageForURL:normalurl
- retinaURL:retinaurl
- useCache:NO
- delegate:delegate
- orBlock:nil];
-}
-
-
-+(ASIHTTPRequest*)loadImageForURL:(NSString*)normalurl
- retinaURL:(NSString*)retinaurl
useCache:(BOOL)use_cache
block:(CLCGImageLoaderCallback)block
{
- return [CLCGImageLoader loadImageForURL:normalurl
- retinaURL:retinaurl
- useCache:use_cache
- delegate:nil
- orBlock:block];
-}
-
-
-+(ASIHTTPRequest*)loadImageForURL:(NSString*)normalurl
- retinaURL:(NSString*)retinaurl
- useCache:(BOOL)use_cache
- delegate:(id<CLCGImageLoaderDelegate>)delegate
- orBlock:(CLCGImageLoaderCallback)block
-{
NSURL *url = nil;
__block ASIHTTPRequest *req = nil;
@@ -97,12 +71,11 @@ +(ASIHTTPRequest*)loadImageForURL:(NSString*)normalurl
if (use_cache) {
UIImage *img = [[[CLCGImageLoader i] cache] objectForKey:[url absoluteString]];
if (img) {
- [self returnImage:img status:200 toDelegate:delegate orBlock:block];
+ [self returnImage:img status:200 block:block];
return nil;
}
}
- __block id<CLCGImageLoaderDelegate> deleg = delegate;
block = [[block copy] autorelease];//make sure it's on the heap
// configure the request
@@ -114,19 +87,19 @@ +(ASIHTTPRequest*)loadImageForURL:(NSString*)normalurl
NSData *data = [req responseData];
UIImage *img = [UIImage imageWithData:data];
if (img == nil) {
- [CLCGImageLoader reportErrorForRequest:req toDelegate:deleg orBlock:block];
+ [CLCGImageLoader reportErrorForRequest:req block:block];
} else {
- if (use_cache)
+ if (use_cache) {
[[[CLCGImageLoader i] cache] setObject:img
forKey:[[req originalURL] absoluteString]];
-
- [self returnImage:img status:[req responseStatusCode] toDelegate:deleg orBlock:block];
+ }
+ [self returnImage:img status:[req responseStatusCode] block:block];
}
}];
// set callback for request failure (usually for no network cases)
[req setFailedBlock:^{
- [CLCGImageLoader reportErrorForRequest:req toDelegate:deleg orBlock:block];
+ [CLCGImageLoader reportErrorForRequest:req block:block];
}];
// execute the request
@@ -142,28 +115,25 @@ +(ASIHTTPRequest*)loadImageForURL:(NSString*)normalurl
+(void)returnImage:(UIImage*)img
status:(int)status
- toDelegate:(id<CLCGImageLoaderDelegate>)deleg
- orBlock:(CLCGImageLoaderCallback)block
-
+ block:(CLCGImageLoaderCallback)block
{
- CLCG_P(@"Status code: %d", status);
+#if DEBUG
+ if (status != 200)
+ CLCG_P(@"Status code: %d", status);
+#endif
+
if (block)
block(img, status);
- else
- [deleg didDownloadImage:img];
}
+(void)reportErrorForRequest:(ASIHTTPRequest*)req
- toDelegate:(id<CLCGImageLoaderDelegate>)deleg
- orBlock:(CLCGImageLoaderCallback)block
+ block:(CLCGImageLoaderCallback)block
{
CLCG_P(@"Status code: %d -- %@", [req responseStatusCode], [req error]);
if (block)
block(nil, [req responseStatusCode]);
- else
- [deleg downloadFailedWithHTTPStatus:[req responseStatusCode]];
}
View
2  CLCGImageView.h
@@ -10,7 +10,7 @@
@class ASIHTTPRequest;
-@interface CLCGImageView : UIImageView <CLCGImageLoaderDelegate>
+@interface CLCGImageView : UIImageView
{
ASIHTTPRequest *mReq;
View
25 CLCGImageView.m
@@ -54,21 +54,20 @@ -(void)loadImageForURL:(NSString*)normalurl retinaURL:(NSString*)retinaurl
CLCG_REL(mReq);
}
- mReq = [CLCGImageLoader loadImageForURL:normalurl retinaURL:retinaurl delegate:self];
+ mReq = [CLCGImageLoader loadImageForURL:normalurl
+ retinaURL:retinaurl
+ useCache:NO
+ block:^(UIImage *img, int http_status) {
+ if (img) {
+ [self setImage:img];
+ } else {
+ CLCG_P(@"Error loading image. HTTP status=%d",
+ http_status);
+ }
+ CLCG_REL(mReq);
+ }];
[mReq retain];
}
--(void)didDownloadImage:(UIImage*)img
-{
- [self setImage:img];
- CLCG_REL(mReq);//we retained in loadImageForURL:retinaURL:, so release here
-}
-
-
--(void)downloadFailedWithHTTPStatus:(int)status
-{
- CLCG_REL(mReq);//we retained in loadImageForURL:retinaURL:, so release here
-}
-
@end
View
2  CLCGLayer.h
@@ -10,7 +10,7 @@
#import "CLCGImageLoader.h"
-@interface CLCGLayer : CALayer <CLCGImageLoaderDelegate>
+@interface CLCGLayer : CALayer
{
ASIHTTPRequest *mReq;
View
36 CLCGLayer.m
@@ -46,27 +46,25 @@ -(void)loadImageForURL:(NSString*)normalurl
}
mCache = cache;
- mReq = [CLCGImageLoader loadImageForURL:normalurl retinaURL:retinaurl delegate:self];
-
- // will release on callbacks
- [mReq retain];
-}
-
--(void)didDownloadImage:(UIImage*)img
-{
- [mCache setObject:img forKey:[[mReq originalURL] absoluteString]];
- [self setContents:(id)[img CGImage]];
+ // don't use the built-in CLCGImageLoader cache if we're using an external cache
+ mReq = [CLCGImageLoader loadImageForURL:normalurl
+ retinaURL:retinaurl
+ useCache:(mCache == nil)
+ block:^(UIImage *img, int http_status) {
+ if (img) {
+ [mCache setObject:img
+ forKey:[[mReq originalURL] absoluteString]];
+ [self setContents:(id)[img CGImage]];
+ } else {
+ CLCG_P(@"Error loading image. HTTP status=%d",
+ http_status);
+ }
+ CLCG_REL(mReq);
+ }];
- // we retained in loadImageForURL:retinaURL:cache:, so release here.
- CLCG_REL(mReq);
-}
-
-
--(void)downloadFailedWithHTTPStatus:(int)status
-{
- // we retained in loadImageForURL:retinaURL:cache:, so release here.
- CLCG_REL(mReq);
+ // will release in the block callback
+ [mReq retain];
}
Please sign in to comment.
Something went wrong with that request. Please try again.