0

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;
}
mackworth
  • 5,873
  • 2
  • 29
  • 49
Trausti Thor
  • 3,722
  • 31
  • 41

3 Answers3

1

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.

0

Not quite sure what you mean by "clickable" - like a UIButton? What behavior do you want to accomplish when a user taps one of the images?

I can't see the immediate problem here, but I can give you information that may help.

Foremost, TTImageView and UIImageView both descend from UIView, TTImageView does not descend from UIImageView (important to note):

UIImageView : UIView
TTImageView : TTView : UIView

We don't know what is going on behind the scenes in UIImageView, so I can't see what is different there, but the documentation seems to make clear that the UIImageView's default behavior for userInteractionEnabled is NO - which is odd, because you are saying that it is working with UIImageView, not the other way around.

Have you tried setting the userInteractionEnabled property to YES on TTImageView?

makdad
  • 6,402
  • 3
  • 31
  • 56
  • Thanks for your answer. AQGridView has a method like TableView where if you click on the "item" you get a notification. I don't get this notification to the AQGridView Delegate. I have tried both resign firstrepsonder and set userinteraction enabled to YES. – Trausti Thor Oct 31 '10 at 19:02
  • Maybe it's better to see the code in the AQGridView, then, where the notification is generated... that may be helpful. – makdad Oct 31 '10 at 23:44
0

The problem here is that TTImageView has userInteractionEnabled to YES. So the touch event is being held by the TTImageView, and AQGridView expects touches in cell Views. Simply add userInteractionEnabled=NO to the TTImageView in your cell and you are ready to go.

LocoMike
  • 5,626
  • 5
  • 30
  • 43