2013-07-16 36 views
0

我做檢查的didSelectRow方法,但我動了表,它消除了檢查 我認爲它創造新的細胞隨着UITableView向上移動,UITableViewCellAccessoryCheckmark會被刪除嗎?

如何使用獨特的細胞,使其不會取代選中單元格選中。

- (void)tableAlert:(SBTableAlert *)tableAlert didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSLog(@"MY INDEX PATH IS %@", indexPath); 

    NSString *email = [allEmails objectAtIndex:indexPath.row]; 

    if (tableAlert.type == SBTableAlertTypeMultipleSelct) { 

     UITableViewCell *cell = [tableAlert.tableView cellForRowAtIndexPath:indexPath]; 

     if (cell.accessoryType == UITableViewCellAccessoryNone){ 
      [cell setAccessoryType:UITableViewCellAccessoryCheckmark]; 
      [selectedEmail addObject:email]; 
     } 

     else{ 
      [cell setAccessoryType:UITableViewCellAccessoryNone]; 
      [selectedEmail removeObject:email]; 

     } 

     [tableAlert.tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 

    NSLog(@"Final Array is %@", selectedEmail); 
} 


- (UITableViewCell *)tableAlert:(SBTableAlert *)tableAlert cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
UITableViewCell *cell; 

    // NSString *identifier = [NSString stringWithFormat:@"%d%d", indexPath.section, indexPath.row]; 


if (tableAlert.view.tag == 0 || tableAlert.view.tag == 1) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; 
} else { 
    // Note: SBTableAlertCell 
    cell = [[SBTableAlertCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; 
} 

//[cell.textLabel setText:[NSString stringWithFormat:@"Cell %d", indexPath.section]]; 

NSString *email = [allEmails objectAtIndex:indexPath.row]; 

cell.textLabel.text = [NSString stringWithFormat:@"%@", email]; 


UIFont *myFont = [ UIFont fontWithName: @"Arial" size: 14.0 ]; 
cell.textLabel.font = myFont; 

return cell; 
} 

回答

0

既然你已經存儲在selectedEmail陣列選定的郵件,你可以利用它在的cellForRowAtIndexPath方法來顯示對號:

NSString *email = [allEmails objectAtIndex:indexPath.row]; 
cell.textLabel.text = [NSString stringWithFormat:@"%@", email]; 
if ([selectedEmail indexOfObject:email] != NSNotFound) { 
    [cell setAccessoryType:UITableViewCellAccessoryCheckmark]; 
} 
else { 
    [cell setAccessoryType:UITableViewCellAccessoryNone]; 
} 

這樣,即使如果該單元被重用,則不會有任何問題。

相關問題