Question

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

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top