UIButton in UITableViewCell

I have a UIButton with an image inside of a UITableViewCell. When the cell is being highlight, the button is also entering the highlighted state (i.e. a darker shade of the image), regardless of whether the user is clicking within the bounds of the button or not.

I don't want this functionality - I only want the button to be highlighted when the button is clicked, not when the entire cell is being clicked.

I've tried to set the image in the highlighted state to be the same as the normal image. This fixes the issue however it stops the button from changing color when it really is highlighted.

Any ideas how to achieve the desired effect?

Answers


This was driving me crazy. I figured out that you need to override setHighlighted:animated: and setSelected:animated:

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];
    self.yourButton.highlighted = NO;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.yourButton.selected = NO;
    // If you don't set highlighted to NO in this method,
    // for some reason it'll be highlighed while the 
    // table cell selection animates out
    self.yourButton.highlighted = NO;
}

Need Your Help

JSONRPC with Grails

grails web-applications json-rpc

I am developing an application using Grails 2.3.8 with Java 7. I am brand new to Grails and I am still learning (after years of Django and Pyramid). While it seems really easy to make a RESTful ser...

Android, how to redraw list when the user sets checkbox?

android listview checkbox redraw

I have a list view and each row contains two textviews and a checkbox.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.