【问题标题】:How to I make check marks appear and disappear when I click multiple rows?单击多行时如何使复选标记出现和消失?
【发布时间】:2013-09-19 11:48:40
【问题描述】:

我想要一个表格,当您单击不同的行时,它们会获得或失去复选标记,以显示它们被选中或未被选中。

目前我的表格视图将让我选择和取消选择不同的行。但是只有在我单击一个然后另一个时才会出现一个复选标记。当我取消选择时也会发生同样的情况,我单击带有复选标记的行,然后单击另一行,复选标记消失。

这是我目前的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * exerciseChoiceSimpleTableIdentifier = @"ExerciseChoiceSimpleTableIdentifier";
    UITableViewCell * exerciseChoiceCell = [tableView dequeueReusableCellWithIdentifier:exerciseChoiceSimpleTableIdentifier];

    if (exerciseChoiceCell == nil) {
        exerciseChoiceCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:exerciseChoiceSimpleTableIdentifier];
    }

    //Here we get each exercise we want to display
    BExercise * exercise = [[_data getExerciseCompleteList] objectAtIndex:indexPath.row];

    //Name the cell after the exercises we want to display
    exerciseChoiceCell.textLabel.text = exercise.name;

    return exerciseChoiceCell;
}

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

    if ([tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryNone)
    {
        // Uncheck the row
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
    // Check the row
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;

    }
}

我认为问题在于它被选中而不是在手指从按钮上松开时在内部进行触摸并取消选择。

我希望答案很直接,但 stackflow 上的所有类似问题都没有处理复选标记延迟出现。

很高兴了解这个问题的根源以及如何解决它。

【问题讨论】:

    标签: ios objective-c uitableview checkbox


    【解决方案1】:

    改变方法

       -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath 
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-11
      • 1970-01-01
      相关资源
      最近更新 更多