我的UITableViewCell原型中有一个UISwitch。UITableView中的UISwitch Bug
问题是,当我打开其中一个开关时,其中一个未显示的开关也打开。
这不会发生在显示所有单元格的iPad版本中。
下面是一些代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
Notification *notification = [notifications objectAtIndex:indexPath.row];
UILabel *titleLabel = (UILabel *) [cell viewWithTag:100];
UISwitch *newsSwitch = (UISwitch *) [cell viewWithTag:101];
UIImageView *imageView = (UIImageView *) [cell viewWithTag:102];
[titleLabel setText:[notification name]];
[imageView setImage:[UIImage imageNamed:[notification image]]];
BOOL isOn = [storage boolForKey:[NSString stringWithFormat:@"notification_%@", [notification name]]];
[newsSwitch setOn:isOn];
[newsSwitch setTag:indexPath.row];
[newsSwitch addTarget:self action:@selector(didChangeStateForSwitch:) forControlEvents:UIControlEventValueChanged];
return cell;
}
你的意思是,还没有在屏幕上的开关也打开?然后这个错误很可能出现在你的'didChangeStateForSwitch:'方法中,请更新你的问题并告诉我们这个方法的代码。 – DarkDust
我从didChangeStateForSwitch中删除了代码:并且行为相同。 –