重用单元格后的 UISwitch Chang 状态



嗨,我在原型单元格上有一个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;
}

非常有趣的代码。起初:我没有看到您尝试创建单元格的位置(取消队列可重用单元格与标识符:仅从可重用队列中挑选对象,我没有看到您将其放在哪里)。在第二:

cell.onOption.on = [data[@"check"] boolValue];

每次单元格应放置在表视图时,您设置字典切换的值。你是否认为你改变了这个值?

附言每次单元格应该变得可见时(您滚动表)都会被调用

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

最新更新