多个复选标记附件在iOS7中无法正常工作

时间:2014-10-27 19:20:31

标签: objective-c xcode uitableview ios7

我有一个UITableview,列出了用户可以选择过滤另一个列表的选项。单击此表视图中的项目时,将显示一个复选标记,如果再次单击该复选标记,则复选标记将消失。允许用户单击多个tableview单元格以同时显示许多单元格上的复选标记。 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;
    }
}

1 个答案:

答案 0 :(得分:2)

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

-(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];

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

注意

即使这不能解决您的问题,您也应该删除该行。它目前的位置没有任何目的。