Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the cell selection style color when once again showing the table view in iphone?

I am new to iphone development.I created a table displaying my contents.If i select a row ,it state is highlighted in blue color and navigates to another view and if i click the back button it navigates back to the table showing the clicked cell in blue color,i want to remove the highlighted color on table while navigating back to its view.How can i do that. Thanks.

like image 746
Warrior Avatar asked May 05 '10 15:05

Warrior


People also ask

How do I turn off cell selection?

Click the table view cell and in the attributes inspector under Table View Cell, change the drop down next to Selection to None.

How do I change the selection color of Uitableviewcell in iOS?

you can just change the backgroundView's backgroundColor property like so: cell. selectedBackgroundView?. backgroundColor = <your color .

How do I change the background color of a table in Swift?

Basic Swift Code for iOS Apps For changing the background color of the table view cell, you should change the contentView. backgroundColor property of the cell. Now run the project to see the effect.


3 Answers

I think the generally accepted way to do this is to deselect the cell as you're navigating to the new view. Instead of viewWillAppear, use the tableview delegate method didSelectRowAtIndexPath and the same deselectRowAtIndexPath you were using.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath{
  [tableView deselectRowAtIndexPath:newIndexPath animated:YES];
}

(and by generally accepted, I mean "stuff I most often see in example code". It depends on what you want it to look like in the end)

like image 181
Nick Avatar answered Sep 21 '22 14:09

Nick


I finally got it by implementing this in my table view class.

- (void)viewWillAppear:(BOOL)animated  
{  
    NSIndexPath *tableSelection = [self.tableView indexPathForSelectedRow];  
    [self.tableView deselectRowAtIndexPath:tableSelection animated:NO];  
}  
like image 36
Warrior Avatar answered Sep 23 '22 14:09

Warrior


You are doing it wrong, on cellForRowAtIndexPath method. use this

 [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

On your UITableViewCells

This would be the correct way if you wanted the cell not to be highlighted nor on selection touch neither on coming back to view. If you only want the cell deselected when coming back to view the other solutions are more suitable.

like image 41
Ganzolo Avatar answered Sep 23 '22 14:09

Ganzolo