1

我正在尝试更改 selected UITableViewCell,但这里发生了一些奇怪的事情。我已经放置了两个图像。请看一下: 在此处输入图像描述在此处输入图像描述

当我选择“早期”单元格时,它变成蓝色。它移动到'early blah blah' UIViewController。然后当我点击 'Find'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];

        }
    }

代码中间的两行:

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

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

4

2 回答 2

5

如果您根本不希望单元格显示选择,请放入cell.selectionStyle = UITableViewCellSelectionStyleNone您的cellForRowAtIndexPath:方法中。

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

[tableView deselectRowAtIndexPath:indexPath animated:YES];

在你的didSelectRowAtIndexPath:

希望这可以帮助

于 2013-08-10T08:59:50.983 回答
1
UITableViewCell* cell = [self tableView:_tableView cellForRowAtIndexPath:indexPath];
// Make sure your cell is not nil.
cell.selectionStyle = UITableViewCellSelectionStyleNone;

我有过这样的情况。

于 2014-01-15T12:36:47.723 回答