2011-03-23 119 views
1

基本上,我有一个包含uiprogressview和uiswitch的每个单元的uitableview。切换开关切换progressview的可见性。在uitableview的每一行中切换uiprogressview的可见性一次切换多个

但是。

如果我切换行中的开关:0。行中的progressview: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; 
} 


} 

任何建议,为什么发生这种情况?

回答

0

你有没有在你的代码中放置一些断点?如果是这样,这个方法被调用两次(一次为0行,一次为11行)还是cellForRowAtIndexPath方法错误地更新行11与行0的可见性?

+0

,如果我的NSLog()从该小区的其他价值,我改变了progressView的知名度..它只输出1行数据......并输出正确的行数据...... – Critter 2011-03-24 12:47:54

+0

这很奇怪。如果我是你,每次进度条的隐藏属性发生变化时,我都会断断续续,并查看程序何时到达这些以及它是如何发生的。 – 2011-03-26 00:17:50

0

因为UITableView重用uitableviewcell以获得更好的性能,所以不能指望每个单元格都是唯一的。 (这种情况下,该行11重用行1单元格),你应该重新在电池的状态:

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