Pregunta

I am using static cells in iOS7 storyboard. The cells have UIButtons in it and they in-turn call the "selectRowAtIndexPath" method.

enter image description here

enter image description here

This is not a consistent behavior and happens only when I switch between the cells.

The two cells here that have the problem have a common superclass. Here's the code:

@implementation StudentMenuMultipleOptionsTableViewCell

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    if (!selected) {
        for (UIView *view in self.contentView.subviews) {
            if ([view isKindOfClass:[BlackBackgroundSelectedButton class]]) {
                BlackBackgroundSelectedButton *button = (BlackBackgroundSelectedButton *)view;
                button.selected = NO;
                [button setWhite];
            }
        }
    }
}

@end
¿Fue útil?

Solución

Quite tricky.

You need to make sure that you are not using the same UIView for multiple cells. The view is resized as soon as it's used once and will create problem with the sizes.

The solution is to create a separate background view for each cell like so:

enter image description here

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top