0
我有一个UItableView
,每一个UITableViewCell
是含有UISwitch
。现在我的问题是,当我将在一个开关点击那我怎么才能OFF
的UITableViewCell
我该如何动态更改UITableView的UISwitch?
在我的代码的其他交换机我已经作出的观点和我可以ON/OFF
开关。但我想要OFF
所有其他交换机,除了我选定的交换机。
请给我一个例子或源代码示例来帮助我。
与问候
编辑
我的代码:由表的数据源使用
- (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] autorelease];
switchview = [[UISwitch alloc] initWithFrame:CGRectZero];
cell.accessoryView = switchview;
switchCondition = NO;
[switchview setOn:NO animated:YES];
[switchview addTarget:self action:@selector(updateSwitchAtIndexPath:) forControlEvents:UIControlEventValueChanged];
[switchview release];
}
if(switchCondition == YES){
[switchview setOn:YES animated:YES];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.contentView.backgroundColor = [UIColor clearColor];
cell.textLabel.text = [NSString stringWithFormat:@"%@",[cellValueArray objectAtIndex:indexPath.row]];
return cell;
}
- (void)updateSwitchAtIndexPath:(UISwitch*)sender {
if(sender.on){
switchCondition = YES;
[table reloadData];
}
}
感谢您快速回答。请给我一个例子,因为我不明白我该怎么做.. – Emon
显示你的代码(更新你的问题)为你的'cellForRowAtIndexPath:'显示你如何设置每一行的开关。同时显示当交换机的值发生变化时用于处理事件的代码。 – rmaddy
我有问题。现在请检查我必须做的事情。 – Emon