【问题标题】:Toggling visibility of uiprogressview in each row of uitableview toggles multiple at once在uitableview的每一行中切换uiprogressview的可见性一次切换多个
【发布时间】:2011-07-21 14:06:12
【问题描述】:

基本上,我有一个 uitableview,每个单元格都包含一个 uiprogressview 和一个 uiswitch。切换开关会切换进度视图的可见性。

但是。

如果我在第 0 行切换开关。 row:0 AND 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;
}


}

关于为什么会发生这种情况的任何建议?

【问题讨论】:

    标签: objective-c uitableview uiswitch uiprogressview


    【解决方案1】:

    您是否在代码中放置了一些断点?如果是这样,此方法是否被调用了两次(一次用于第 0 行,一次用于第 11 行)还是 cellForRowAtIndexPath 方法错误地使用第 0 行的可见性更新了第 11 行?

    【讨论】:

    • 如果我 NSLog() 来自该单元格的另一个值,因为我正在更改 progressView 的可见性..它只输出 1 行数据...并且它正在输出正确行的数据...
    • 这很奇怪。如果我是你,我会在每次进度条的隐藏属性更改时断点,并查看程序何时到达这些以及它是如何做到的。
    【解决方案2】:

    由于 UITableView 重用 uitableviewcell 以获得更好的性能,因此您不能指望每个单元格都是唯一的。 (这种情况下第 11 行重复使用第 1 行单元格),您应该重置单元格的状态:

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

    【讨论】:

      猜你喜欢
      • 2012-04-28
      • 1970-01-01
      • 2013-07-12
      • 1970-01-01
      • 2016-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多