【问题标题】:Multiple checkmark accessory not working properly in iOS7多个复选标记附件在 iOS7 中无法正常工作
【发布时间】:2014-10-27 19:20:31
【问题描述】:

我有一个 UITableview,它列出了用户可以选择用来过滤另一个列表的选项。当单击此表格视图中的项目时,会出现一个复选标记,如果再次单击它,复选标记就会消失。允许用户单击多个 tableview 单元格以同时在许多单元格上显示复选标记。表格视图也分为多个部分。

这在 iOS 8 上一切正常,但是当我在 iOS 7 上运行它时,当我单击单元格时,复选标记不会出现。如果我转到另一个视图然后返回到 tableview 复选标记就在那里。我在stackoverflow上搜索了其他帖子,这些帖子建议我应该尝试将单元格的色调设置为黑色,我尝试过但不起作用。

我还用带有复选标记图像的自定义单元格替换了复选标记,我将其取消隐藏和隐藏。当我单击它们时,这里会显示复选标记,但是当我再次单击它们时,它不会消失。为了清楚起见,我将附上下面的代码。

@property NSMutableArray *favorite;
@property NSMutableArray *favoriteCheckmark;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FilterCell *cell = [tableView dequeueReusableCellWithIdentifier:@"filtercell" forIndexPath:indexPath];
switch (indexPath.section) {
    case 0:
        cell.textLabel.text = [favorite objectAtIndex:indexPath.row];
        if ([favoriteCheckmark containsObject:indexPath]){
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }else{
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
        break;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
FilterCell *cell = [tableView dequeueReusableCellWithIdentifier:@"filtercell" forIndexPath:indexPath];
switch (indexPath.section) {
    case 0:
        cell.textLabel.text = [favorite objectAtIndex:indexPath.row];
        if ([favoriteCheckmark containsObject:indexPath]){
            [favoriteCheckmark removeObject:indexPath];
        }else{
            [favoriteCheckmark addObject:indexPath];
        }
        break;
    }
}

【问题讨论】:

    标签: objective-c xcode uitableview ios7


    【解决方案1】:

    我不是很肯定,但这可能与它有关:

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    FilterCell *cell = [tableView dequeueReusableCellWithIdentifier:@"filtercell" forIndexPath:indexPath];
    switch (indexPath.section) {
        case 0:
            cell.textLabel.text = [favorite objectAtIndex:indexPath.row];
            if ([favoriteCheckmark containsObject:indexPath]){
                [favoriteCheckmark removeObject:indexPath];
            }else{
                [favoriteCheckmark addObject:indexPath];
            }
            break;
        }
    }
    

    你来电:

    FilterCell *cell = [tableView dequeueReusableCellWithIdentifier:@"filtercell" forIndexPath:indexPath];
    

    Press 已打开,它正在排队一个新的单元格,并且可能会导致问题。尝试删除该行,看看会发生什么。

    注意

    即使这不能解决您的问题,您也应该删除该行。它无法在当前位置发挥作用。

    【讨论】:

    • 另外,在 didSelectRowAtIndexPath 方法中没有 reloadData 调用来更新 UI 以匹配新更新的模型。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-02
    • 1970-01-01
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    相关资源
    最近更新 更多