Search code examples
iphonethree20aqgridview

Using TTImageView with AQGridView


I created a custom AQGridViewCell.

By using UIImageView everything works. The image appears and is clickable, but when I change the UIImageView to TTImageView I can't click on the image.

The same example as here below by just changing the imageview to UIImageView and the the setter message to an image, everything works as expected.

Here is my ImageGridCell.h

#import "AQGridViewCell.h"
#import <Three20/Three20.h>

@interface ImageGridCell : AQGridViewCell
{
    TTImageView * _imageView;
 NSString *urlPath;
}
@property (nonatomic, retain) NSString *urlPath;

@end

And here is my ImageGridCell.m

#import "ImageGridCell.h"

@implementation ImageGridCell
@synthesize urlPath;

- (id) initWithFrame: (CGRect) frame reuseIdentifier: (NSString *) aReuseIdentifier
{
    self = [super initWithFrame: frame reuseIdentifier: aReuseIdentifier];
    if ( self == nil )
        return ( nil );

    _imageView = [[TTImageView alloc] initWithFrame: CGRectMake(0, 0, 100, 100)];
 [_imageView setContentMode:UIViewContentModeScaleAspectFit];
    [self.contentView addSubview: _imageView];
    return ( self );
}

- (void) dealloc
{
    [_imageView release];
    [super dealloc];
}

- (CALayer *) glowSelectionLayer
{
    return ( _imageView.layer );
}

- (UIImage *) image
{
    return ( _imageView.image );
}
-(void)setUrlPath:(NSString *)urlpath {
 _imageView.urlPath = urlpath;
}

Solution

  • I faced the same situation, and here is the solution I came with. My AQGridViewCell have both a TTImageView and a UIImageView. I use the TTImageView to load the image, and when it's loaded, I pass it to the UIImageView which displays it.

    To do that, my AQGridViewCell subclass implements the TTImageViewDelegate protocol. In my PostGridViewCell.h, I have :

    @interface PostGridViewCell : AQGridViewCell <TTImageViewDelegate> {
        @private
        TTImageView *ttImageView_;
        UIImageView *imageView_;
    }
    // @property here …
    @end
    

    In my implementation file, in the initWithFrame:reuseIdentifier: method, I init both my ttImageView and my imageView, but I only add the imageView as a subview of my cell. And I set the ttImageView delegate property to self (so I can be notified when the image is loaded) :

    - (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)aReuseIdentifier {
        if ((self = [super initWithFrame:frame reuseIdentifier:aReuseIdentifier])) {
            // init image
            ttImageView_ = [[TTImageView alloc] initWithFrame:CGRectZero];
            ttImageView_.delegate = self;
            imageView_ = [[UIImageView alloc] initWithFrame:CGRectZero];
            [self.contentView addSubview:imageView_];
            // …
        }
        return self;
    }
    

    When the TTImaveView has loaded the image, it calls the imageView:didLoadImage: method on the delegate (which is the PostGridViewCell). In my implementation file, I have this method :

    - (void)imageView:(TTImageView*)imageView didLoadImage:(UIImage*)image {
        self.imageView.image = image;
        [self setNeedsLayout];
    }
    

    Does it help?
    Cheers,
    Thomas.