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.
Click the table view cell and in the attributes inspector under Table View Cell, change the drop down next to Selection to None.
you can just change the backgroundView's backgroundColor property like so: cell. selectedBackgroundView?. backgroundColor = <your color .
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.
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)
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];
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With