1

選択した を変更しようとしていますUITableViewCellが、ここで少し奇妙なことが起こっています。2枚の画像を配置しました。ご覧ください: ここに画像の説明を入力ここに画像の説明を入力

「早い」セルを選択すると、青色に変わります。それは「初期の何とか」に移動し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];

        }
    }

コードの真ん中にある 2 行:

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

この 2 行は機能しませんでした。これを修正する方法を知っている人はいますか?

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 に答える