1

Basically I have a uitableview with each cell containing a uiprogressview and a uiswitch. toggling the switch toggles the visibility of the progressview.

but.

if I toggle the switch in row:0. the progressview in row:0 AND row:11 shows.

my switch has this: [(UISwitch *)cell.accessoryView addTarget:self action:@selector(PrefetchStudy:) forControlEvents:UIControlEventValueChanged];

and here is the action:

-(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;
}


}

any suggestions as to why this is happening?

Critter
  • 462
  • 1
  • 3
  • 14

2 Answers2

0

Since UITableView reuse uitableviewcell for better performance, you can't count on each cell is unique. (this case the row 11 reuses the row 1 cell), you should reset the state of the cell in:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
David
  • 3,843
  • 33
  • 36
0

Have you put some breakpoints in your code? If so, is this method being called twice (once for row 0 and once for row 11) or is the cellForRowAtIndexPath method incorrectly updating row 11 with row 0's visibility?

Kristian K
  • 51
  • 1
  • 5
  • if I NSLog() another value from that cell as I am changing the visibility of the progressView.. it only output's 1 row of data... and it's outputting the correct row's data... – Critter Mar 24 '11 at 12:47
  • that's strange. if I were you I would just breakpoint every time that a progressbar's hidden property changes, and see when the program reaches those and how it does. – Kristian K Mar 26 '11 at 00:17