我翻一個簡單的BOOL值是這樣的:簡單布爾切換不起作用?
active = !active;
NSLog(@"%@", active? @"active" : @"not active");
我已經這樣做了無數次,但現在,由於某種原因,它不工作,這真的得罪我了。當流量在這裏遇到時,它總是打印「活動」。這不是開關!
這裏是我的界面:
@interface HeaderView : UIView {
UILabel *label;
UIButton *button;
UIImageView *background;
BOOL active;
int section;
__weak id<HeaderViewDelegate> delegate;
}
和功能在其中執行操作:
- (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];
}
感謝
我想知道,默認情況下會將其設置爲YES,因爲您沒有爲其分配任何值,所以如果您總是運行它,並且每次運行它時都默認設置爲默認值,那麼它總是會有相同的結果。我不確定是否是這種情況。 – pasawaya