UITableViewCellSelectionStyleNone不起作用

boo*_*224 1 iphone objective-c uitableview

我正在尝试更改所选内容UITableViewCell,但这里发生了一些奇怪的事情.我放了两张图片.请看一下: 在此输入图像描述在此输入图像描述

当我选择"早期"单元格时,它会变为蓝色.它转向'早期的等等' UIViewController.然后当我点击"查找"时UIButton,它会回到第一个视图.它工作,但细胞仍然选择蓝色!所以我写了一些代码如下:

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

    if ([_currentMethod isEqual: @"searchIt"]) {

        if (indexPath.row == 0) {
            BookMark2ViewController* bookMark2 = [[BookMark2ViewController alloc] init];


            UITableViewCell* cell = [self tableView:_tableView
                                            cellForRowAtIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;



            [self.navigationController pushViewController:bookMark2 animated:YES];

        }else if (indexPath.row == 1) {
            BookMarkViewController* bookMark1 = [[BookMarkViewController alloc] init];

            [self.navigationController pushViewController:bookMark1 animated:YES];

        }
    }
Run Code Online (Sandbox Code Playgroud)

代码中间的两行:

        UITableViewCell* cell = [self tableView:_tableView
                                        cellForRowAtIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
Run Code Online (Sandbox Code Playgroud)

这两行没有用.有谁知道如何解决这一问题?

KDa*_*ker 5

如果您不希望单元格显示选择,请将其cell.selectionStyle = UITableViewCellSelectionStyleNone放在cellForRowAtIndexPath:方法中.

如果要选择单元格然后取消选择,请放置

[tableView deselectRowAtIndexPath:indexPath animated:YES];
Run Code Online (Sandbox Code Playgroud)

在你的 didSelectRowAtIndexPath:

希望这可以帮助