初始值:self.conditionState = 5;
//1:收件人=1 10:发件人=2 100:标题=4 1000:内容=8
- (IBAction)checkedbox:(id)sender {
UIButton *button = (UIButton *)sender;
button.selected = !button.selected;
int tmp = 1;
// NSLog(@"%d",button.tag);
// NSLog(@"%d",self.conditionState);
tmp = tmp << button.tag;
// NSLog(@"tmp:%d",tmp);
if (button.selected) {
self.conditionState |= tmp;
}else{
self.conditionState &= ~tmp;
}
// NSLog(@"%d",self.conditionState);
}
//1:添加LIKE 操作 0:不添加LIKE操作
-(int) isAppendSQL:(int)num withState:(int)state
{
int tmp = 1;
tmp = tmp << num;
tmp &= state;
//NSLog(@"%d",tmp);
return tmp;
}
本文介绍了一个iOS应用中实现条件状态管理的方法。通过使用位运算来更新和维护UI按钮的状态,实现了高效的状态切换。文中详细解释了如何通过按钮的tag属性来计算状态,并通过位运算符来设置和取消条件。
1871

被折叠的 条评论
为什么被折叠?



