boochan224
boochan224

Reputation: 381

UITableViewCellSelectionStyleNone not working

I am trying to change the selected UITableViewCell, but a little weird thing is happening here. I have placed the two images. Please take a look: enter image description hereenter image description here

When I select the 'early' cell, it turns blue. It moves to the 'early blah blah' UIViewController. Then when I hit the 'Find' UIButton, it goes back to the first view. It works, but the cell is still selected blue! So I wrote some code as below:

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

        }
    }

The two lines right in the middle of the code:

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

These two lines didn't work. Does any one know how to fix this?

Upvotes: 1

Views: 3914

Answers (2)

Alexmelyon
Alexmelyon

Reputation: 1239

UITableViewCell* cell = [self tableView:_tableView cellForRowAtIndexPath:indexPath];
// Make sure your cell is not nil.
cell.selectionStyle = UITableViewCellSelectionStyleNone;

I had a such situation.

Upvotes: 1

KDaker
KDaker

Reputation: 5909

If you dont want the cells to show selection at all, place cell.selectionStyle = UITableViewCellSelectionStyleNone in your cellForRowAtIndexPath: method.

if you want the cell to be selected and then deselect, place

[tableView deselectRowAtIndexPath:indexPath animated:YES];

in your didSelectRowAtIndexPath:

hope this helps

Upvotes: 5

Related Questions