我的 TableViewController 中有简单的代码:
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if(debug == 1){
NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd));
}
static NSString *cellIndetifier = @"Student Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndetifier
forIndexPath:indexPath];
Student *student = [self.frc objectAtIndexPath:indexPath];
NSMutableString *title = [NSMutableString stringWithFormat:@"%@", student.name];
[title replaceOccurrencesOfString:@"(null)"
withString:@""
options:0
range:NSMakeRange(0, [title length])];
cell.textLabel.text = title;
if (cell == nil) {
cell.textLabel.textColor = [UIColor whiteColor];
}
if ([self.checkedIndexPaths containsObject:indexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
if(debug == 1){
NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd));
}
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
self.checkedIndexPaths = [self initializationNSSet:self.checkedIndexPaths];
if ([self.checkedIndexPaths containsObject:indexPath])
{
[self.checkedIndexPaths removeObject:indexPath];
cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
[self.checkedIndexPaths addObject:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
代码工作正常,当我使用 DetailButton 和 DetailDisclosureButton 而不是 Checkmark 和 None 时,但是当我使用 checkmark 并且 none 时,表格视图的行在这两种情况下都不可点击(方法ableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
未被调用)。我该怎么做才能更改复选标记和无(也许可以点击整行)。当我再次单击它时,我需要多行带有复选标记并删除选中的行。