-1

我有一个 Uitableview,它的附件类型设置为“CheckMark”,如果选择了单元格(选中)我想将单元格的内容添加到数组中,如果未选中,我想从数组中删除相同的内容。

我已将此代码添加到tableView:didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    

UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
NSIndexPath *tableSelection = [listingSet indexPathForSelectedRow];

if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
    cell.accessoryType = UITableViewCellAccessoryNone;
    [listingSet deselectRowAtIndexPath:tableSelection animated:YES];
} 
else {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    ID = [NSString stringWithFormat:@"%@",[[ParsedData valueForKey:@"ID"]objectAtIndex:indexPath.row]];
    NSLog(@"++++++IDSSS %@",ID);
    NSString *titlename = [NSString stringWithFormat:@"%@.%@",[[ParsedData valueForKey:@"UserFileName"]objectAtIndex:indexPath.row],[[ParsedData valueForKey:@"fileExtension"]objectAtIndex:indexPath.row]];                                                                                                            
    [Selectedfiles addObject:ID];
    [Selectedfiles retain];
    NSLog(@"++++++Titlesss %@",Selectedfiles);
    [listingSet deselectRowAtIndexPath:tableSelection animated:YES];
  }
}
4

1 回答 1

0

tableView:didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    

UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
NSIndexPath *tableSelection = [listingSet indexPathForSelectedRow];

ID = [NSString stringWithFormat:@"%@",[[ParsedData valueForKey:@"ID"]objectAtIndex:indexPath.row]];    

if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {

     // Remove id 
     [Selectedfiles removeObject:ID];
    cell.accessoryType = UITableViewCellAccessoryNone;
    [listingSet deselectRowAtIndexPath:tableSelection animated:YES];
} 
else {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    // Add id 
     [Selectedfiles addObject:ID];

    NSLog(@"++++++IDSSS %@",ID);
    NSString *titlename = [NSString stringWithFormat:@"%@.%@",[[ParsedData valueForKey:@"UserFileName"]objectAtIndex:indexPath.row],[[ParsedData valueForKey:@"fileExtension"]objectAtIndex:indexPath.row]];                                                                                                            


    NSLog(@"++++++Titlesss %@",Selectedfiles);
    [listingSet deselectRowAtIndexPath:tableSelection animated:YES];
  }
}
于 2013-05-24T09:01:39.723 回答