在目标c中是否可以通过引用传递布尔值?我有许多布尔属性需要管理,所以我想将这些值的切换封装到一个函数中,我可以从每个按钮单击事件中调用它.这是一个例子:
@interface MyViewController() @property (nonatomic) BOOL *sendEmails; @end
然后在UIButton
点击事件中,我有这个方法调用:
[self updateEmailPreference:self.sendEmails button:self.noEmailsCheckBox];
哪个调用此方法:
- (void) updateEmailPreference : (BOOL *) b button : (UIButton *) button { if (*b) {*b = NO;} else {*b = YES;} if (*b) { [button setBackgroundImage:[UIImage imageNamed:@"checked_checkbox"] forState:UIControlStateNormal]; } else { [button setBackgroundImage:[UIImage imageNamed:@"unchecked_checkbox"] forState:UIControlStateNormal]; } }
但不幸的是,这个崩溃了if (*b)...
.这可能吗?谢谢!