Custom UIButton cannot interact with associated UIImageView

I adhere to the following code. Some of how my UIButton Extended class cannot show or hide UIImageView

My methods are called, and the image is not zero.

Here is the code:

@interface UILinkedImageButton : UIButton {
    IBOutlet UIImageView *linkImageView;
}

@property (nonatomic, retain) IBOutlet UIImageView *linkImageView;

@end

#import "UILinkedImageButton.h"

@interface UILinkedImageButton ()
- (void)showImage;
- (void)hideImage;
@end
-------------------------------------------------------------------------------------------------

@implementation UILinkedImageButton


@synthesize linkImageView;

- (void) dealloc{

    [linkImageView release], linkImageView = nil;
    [super dealloc];
}

- (id) initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];

    if(self){
        [self addTarget:self action:@selector(showImage) forControlEvents:UIControlEventTouchDown];
        [self addTarget:self action:@selector(hideImage) forControlEvents:UIControlEventTouchUpInside];
        [self addTarget:self action:@selector(hideImage) forControlEvents:UIControlEventTouchUpOutside];
    }

    return self;
}

- (void)showImage
{
    if(self.imageView){
        NSLog(@"UILinkImageButton - showImage - currentStatus: %@", self.imageView);
        self.imageView.hidden = NO;
        [self.superview layoutIfNeeded];
    }   
}

- (void)hideImage
{
    if(self.imageView){
        NSLog(@"UILinkImageButton - hideImage");
        self.imageView.hidden = YES;
    }
}

@end
+3
source share
1 answer

As Thomas Müller notes in the commentary, I also think that actions should be in the controller.

, imageView, , , "linkImageView". , 'imageView' - readonly , UIButton, , linkImageView.

, .

, Swapnil

+2

Source: https://habr.com/ru/post/1753840/


All Articles