【发布时间】:2019-06-01 18:30:09
【问题描述】:
所以我有一个 UISwitch,它的 backgroundColor 已经在 tableViewCell.m 中设置为 clearColor:
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
{
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor colorWithHexString:@"#333333"];
[self initUI];
}
return self;
}
- (void)initUI {
[self addSubview:self.topLine];
[self addSubview:self.imgView];
[self addSubview:self.titleLab];
[self addSubview:self.rightView];
[self addSubview:self.rightSwitch];
[self addSubview:self.cellLine];
[self addSubview:self.bottomLine];
}
- (UISwitch *)rightSwitch {
if (!_rightSwitch) {
self.rightSwitch = [[UISwitch alloc] init];
self.rightSwitch.frame = CGRectMake(253*kScaleXAndWidth, 8*kScaleYAndHeight, 51*kScaleXAndWidth, 31*kScaleYAndHeight);
self.rightSwitch.hidden = YES;
[self.rightSwitch setBackgroundColor:[UIColor clearColor]];
[self.rightSwitch addTarget:self action:@selector(rightSwitchClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _rightSwitch;
}
rightSwitchClick 是一个块,然后在 cellForRowAtIndexPath TableViewController.m 中:
QuickLoginCell *cell = [tableView dequeueReusableCellWithIdentifier:QuickLoginCellID forIndexPath:indexPath];
cell.rightView.hidden = YES;
cell.rightSwitch.hidden = NO;
__block QuickLoginCell *blockCell = cell;
if (isIDlogin) {
[cell.rightSwitch setEnabled:NO];
}
else{
[cell.rightSwitch setEnabled:YES];
}
cell.rightSwitch.on = NO;
cell.bottomLine.hidden = NO;
if (![BetwayUtils isEmptyString:patternLock]) {
cell.rightSwitch.on = YES;
cell.bottomLine.hidden = YES;
}
[cell.imgView setImage:[UIImage imageNamed:@"ic_patternLock"]];
cell.rightSwitchAddClick = ^{
if (blockCell.rightSwitch.on) {
PatternLockViewController *vc = [PatternLockViewController new];
[strongSelf.navigationController pushViewController:vc animated:YES];
}
else{
}
};
所以当打开它会直接进入PatternLockViewController,并且在我设置完patternLock后它会再次弹出到TableViewController并且现在将打开开关。问题是当我尝试将其关闭时,背景颜色突然变为白色:
当我删除时:
PatternLockViewController *vc = [PatternLockViewController new];
[strongSelf.navigationController pushViewController:vc animated:YES];
所以在块内没有代码并且 UISwitch backgroundColor 是 clearColor,我尝试打开和关闭它,它按预期工作。所以我对这件事有点困惑,因为我没有在任何地方将 UISwitch backgroundColor 设置为白色。
更新
已经尝试在从 patternlockviewcontroller 弹出时使用委托刷新表,但仍然无济于事
【问题讨论】:
-
请显示完整的 cellForRowAtIndexPath 代码以及调用 rightSwitch 的自定义单元格中的代码。
-
@danh 更新问题
标签: ios objective-c uiswitch