我UITableView
在每个cell
. 我就是这样做的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CustomCellIdentifier = @"CustomCellIdentifier ";
ExtraCell *eCell = (ExtraCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (eCell == nil) {
NSArray *nib;
nib = [[NSBundle mainBundle] loadNibNamed:@"ExtraCell" owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[ExtraCell class]])
eCell = (ExtraCell *)oneObject;
}
int flag = (1 << indexPath.row);
// update row's accessory if it's "turned on"
if (checkboxSelections & flag)
eCell.accessoryType = UITableViewCellAccessoryCheckmark;
eCell.selectionStyle = UITableViewCellSelectionStyleNone;
return eCell;
}
AndUITableView
的didSelectRowAtIndexPath
方法如下
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
checkboxSelections ^= (1 << indexPath.row);
[self.tblViewExtra reloadData];
NSLog(@"CheckBox selections %d", checkboxSelections);
}
这里,checkboxSelections
是一个NSUInteger
。checkboxSelections
将所有选定的行累积为该整数的单个位。我的问题是如何将选定的行作为数组或一组行号获取?