I am flipping the value of a simple BOOL like this:
active = !active;
NSLog(@"%@", active? @"active" : @"not active");
I’ve done this numerous times but right now, for some reason it’s not working and it’s really pissing me off. When ever the flow hits here, it always prints “active”. It’s not switching!!
Here’s my interface:
@interface HeaderView : UIView {
UILabel *label;
UIButton *button;
UIImageView *background;
BOOL active;
int section;
__weak id<HeaderViewDelegate> delegate;
}
and function where the action is performed:
- (void)actionTUI:(id)sender {
active = !active;
NSLog(@"%@", active? @"active" : @"not active");
UIImage *image = nil;
if (active) {
image = [UIImage imageNamed:@"active.png"];
} else {
image = [UIImage imageNamed:@"unactive.png"];
}
[button setBackgroundImage:image forState:UIControlStateNormal];
[delegate headerView:self toggled:active];
}
Thanks
Ok, the problem was that after toggling, I was reloading the tableview which apparently recalls:
which caused a new header view to be allocated/initialized with active set to NO and right after toggling, set to YES. That’s why every time, even after flipping the values it was set to active (because right after, it would get discarded and a new header view would come to it’s place).