Вопрос

I'm using a UITableView and a custom cell with a checkbox. I have more than 1 section. When a check a checkbox in the first section, for example the cell with row = 0 and section = 0, I save the data and it works. But the cell in the row = 0 and section = 1 is also checked! How can I make the difference between those sections ?

Thank you so much!

Это было полезно?

Решение

Following sample code will help you for your situation.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
       cell = (CustomCell *) [[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] objectAtIndex:0];
       cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.checkBox = [self fillCheckBoxStatus:indexPath];//This method will say about check box whether going to SET or NOTSET. 
    //...
    return cell;
}

Другие советы

use dequeueReusableCellWithIdentifier to nil like bellow...

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
    if (cell == nil) {

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil] autorelease];
      ////you another code..
   }
  return cell;
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top