OGeek|极客世界-中国程序员成长平台

标题: ios - UITableView 中需要多次点击以进行复选标记 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 16:12
标题: ios - UITableView 中需要多次点击以进行复选标记

温柔点,我在学习。

下面的代码实际上可以正常工作,除了在我第一次点击一行(适本地放置一个复选标记)之后,我必须点击一个单元格两次才能让它删除相同的复选标记。

同样,在删除它之后,它需要点击两次才能将复选标记放回去。

我该如何解决这个问题?

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath
{
    UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
    NSInteger selectedRow = indexPath.row;

    if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
        thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
        if (selectedRow == 0) dm = 1;
        else if (selectedRow == 1) athero1 = 1;
        else if (selectedRow == 2) athero2 = 1;
        else if (selectedRow == 3) athero3 = 1;
        else if (selectedRow == 4) familyHistory1 = 1;
        else if (selectedRow == 5) familyHistory2 = 1;
    }
    else  {
        thisCell.accessoryType = UITableViewCellAccessoryNone;
        if (selectedRow == 0) dm = 0;
        else if (selectedRow == 1) athero1 = 0;
        else if (selectedRow == 2) athero2 = 0;
        else if (selectedRow == 3) athero3 = 0;
        else if (selectedRow == 4) familyHistory1 = 0;
        else if (selectedRow == 5) familyHistory2 = 0;
    }
}



Best Answer-推荐答案


确保 allowsMultipleSelection 未设置为 YES。不使用该属性时设置的默认值为NO。如果您在类(class)的任何地方使用此属性,请尝试将其设置为 NO 以检查它是否有效。这将导致需要点击 2 次才能选择一行。

self.tableView.allowsMultipleSelection = NO;

关于ios - UITableView 中需要多次点击以进行复选标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12335728/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4