Naor Levi
Naor Levi

Reputation: 117

Action not happening when tapping UIButton

I have a UIButton placed on a UIImageView and UILabel. When i press down the button i want an image to show in the UIImageView and the text color of the UILabel to be changed, and when i pull up my finger i want the image to disappear and the text color of the UILabel changed back to black.

- (void)highlightActivity:(id)sender {
    activityImage.image = [UIImage imageNamed:[[NSMutableString alloc] initWithString:activityName]];

    activityLabel.textColor = activityColor;
}

- (void)deHighlightActivity:(id)sender {
    activityLabel.textColor = [UIColor blackColor];
    activityImage.image = nil;
}

It works fine when i press the button and then release, but i have a problem when tapping the button, the image isn't showing at all and the text color isn't changing.

Any ideas how to make it happen when tapping too?

Thanks, Naor.

Upvotes: 0

Views: 113

Answers (1)

Xu Yin
Xu Yin

Reputation: 3940

I think the problem is you attach both

    Touch Up inside and outside on deHighlightActivity.

Because, when you pressed the button, you will release (touch up) the button eventually, if you put both touch up inside and outside on deHighlightActivity, that action will be called every time. So that your tapping action calls deHighlightActivity as well.

I don't know what exactly you are trying to do here, but looks like you have some conflicts on your design.

Upvotes: 1

Related Questions