基本上,我有一个uitableview,每个单元格都包含一个and进程视图和一个uiswitch。切换开关可切换进度视图的可见性。
但。
如果我在第0行切换开关。显示了row:0和row:11中的进度视图。
我的开关有这个:(UISwitch *)cell.accessoryView addTarget:self action:@selector(PrefetchStudy:) forControlEvents:UIControlEventValueChanged;
下面是它的动作:
-(void)PrefetchStudy:(id)sender
{
UISwitch *tmpSwitch = (UISwitch*)sender;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:tmpSwitch.tag inSection:0];
CustomCell *cell = (CustomCell *)[self.tableview cellForRowAtIndexPath:indexPath];
NSString *tmp = cell.patient_name.text;
NSLog(@"This is the patient name of the selected row: %@", tmp);
if(tmpSwitch.on)
{
cell.progressBar.hidden = NO;
}
else
{
cell.progressBar.hidden = YES;
}
}
对于为什么会发生这种情况,有什么建议吗?
发布于 2011-03-24 03:58:57
你在你的代码中设置断点了吗?如果是这样,这个方法是否被调用了两次(一次用于第0行,一次用于第11行),或者是cellForRowAtIndexPath方法错误地使用行0的可见性更新了第11行?
发布于 2012-09-21 15:55:57
由于UITableView重用uitableviewcell以获得更好的性能,所以您不能指望每个cell都是唯一的。(在本例中,第11行重用了第1行单元格),则应在以下位置重置单元格的状态:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
https://stackoverflow.com/questions/5410346
复制相似问题