我創建了UITableView
,每個cell
上都有一個複選框。這是我做的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;
}
而且UITableView
的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
將所有選定的行累加爲該整數的單個位。我的問題是如何將選定的行作爲一個數組或一組行數?
如果我理解正確QN,你爲什麼不以一個NSMutableArray在'didSelectRowAtIndexPath'添加行? – HRM
@sajaz你在你的數組中存儲什麼?任何類對象? –
checkboxSelections^=(1 << indexPath.row); ??????你能解釋一下嗎? – Rajneesh071