Luda
Luda

Reputation: 7058

Cannot disable highlighting the first time UITableView selected?

I have implemented cell.selectionStyle = UITableViewCellSelectionStyleNone; both in:

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { }

and in:

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

But each row keeps geting blue selection first time it is clicked. How can I disable the selection entirely?

The code goes like this (The cell is custom):

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath     *)indexPath
{    
    CategoryCell *cell = (CategoryCell*)[tableView cellForRowAtIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;  
    return nil;
}

Upvotes: 0

Views: 1210

Answers (3)

Apurv
Apurv

Reputation: 17186

cell.selectionStyle = UITableViewCellSelectionStyleNone;

You should do it in cellForRowAtIndexPath

Upvotes: 0

Michael Dautermann
Michael Dautermann

Reputation: 89509

Turn the "allowsSelection" property off for your table.

You can do this programatically or within the XIB / storyboard file.

Upvotes: 0

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

Implement it in cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    //create cell
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

   return cell;

}

Upvotes: 2

Related Questions