Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell setSelected method not getting called

I am on iOS7 and have a UITableViewCell subclass for my UITableView with static cells. I am overriding the setSelected method in the implementation.

For some reason, the method only gets called when the table loads but doesn't get called when the cell is actually tapped and selected.

What am I doing wrong here? How do I get it to work?

@implementation StudentMenuMultipleOptionsTableViewCell

- (void)setSelected:(BOOL)selected {
    [super setSelected:selected];
    if (selected) {
        UIView *view = [UIView new];
        view.backgroundColor = [UIColor colorWithRed:0.542 green:0.788 blue:0.060 alpha:1.000];
        self.selectedBackgroundView = view;
    }
    else {
        for (UIView *view in self.subviews) {
            if ([view isKindOfClass:[BlackBackgroundSelectedButton class]]) {
                BlackBackgroundSelectedButton *button = (BlackBackgroundSelectedButton *)view;
                button.selected = NO;
                [button setWhite];
            }
        }
    }
}

@end

ScreenShot

like image 629
NSF Avatar asked Apr 03 '14 14:04

NSF


1 Answers

The problem was that I was using the setSelected method. The method that needs to be used for the newer iOS versions is:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated;
like image 54
NSF Avatar answered Sep 20 '22 08:09

NSF