Я использую раскадровку и автоматический макет. Я добавляю UISwitch в свою ячейку с тегом 5. Когда я выбираю первый UISwitch и прокручиваю вниз, я вижу, что другой UISwitch также включен, и если я прокрутку вверх, мой первый UISwitch отключается. Как это исправить?UITableView с UISwitch
Мой код:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UISwitch* switchView = (UISwitch *)[cell viewWithTag:5];
[switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
return cell;
}
его из клетки reusablity ... вам нужно хранить indexpath не на swithces и на основе этого заполнить вашу ячейку –