【发布时间】:2013-12-25 09:51:39
【问题描述】:
您好,我在原型单元格上有一个UISwitch。
当我将UISwitch 更改为OFF 并通过滚动将单元格移出UITableView 框架然后向后滚动时-UISwitch 是ON。
但是进行了更改 - 因为当我再次调用 UITableView 控制器以显示在屏幕上时 - UISwitch 是 OFF。
代码是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
SettingsOptionCell * cell = [tableView dequeueReusableCellWithIdentifier: @"SettingsOptionCell"];
NSDictionary *data = [NSDictionary new];
cell.onOption.hidden = NO;
switch (indexPath.section) {
case SettingsControllerServiceSection:
data = self.serviceAttr[indexPath.row];
break;
case SettingsControllerStatusSection:
data = self.statusAttr[indexPath.row];
break;
default:
break;
}
cell.captionLabel.text = data[@"name"];
cell.onOption.on = [data[@"check"] boolValue];
cell.optionId = data[@"id"];
cell.updateHandler = ^(){
if (self.updateHandler) {
[self update];
self.updateHandler();
}
};
return cell;
}
【问题讨论】:
-
可能与您的
updateHandler有关? -
请分享
SettingsOptionCell类的代码 -
在更改开关时将字典中的数据值检查设置为 ON 或 OF。发生这种情况是因为字典中的检查数据相同,最好你做一件事尝试在 Swith 时使用 BOOL 值在 dictinoray 中或在 dictinoray 中,那么我认为您的问题已解决,必须使数据数组全局化
标签: ios objective-c uitableview uiswitch