Table cell borders become visible when cell is selected in UITableView in IOS
I have a third party menu for my ios app being developed. I used a UITableViewController as my menu and I want to highlight the selected menu item. I did highlight and the problem is that when I select one of these menu items, the visibility goes up and down the borders of the table cell.
This is my side menu and look at the selected table cell (menu item). there are top and bottom borders of cells or something like that.
This is my code I used to highlight the selected cell
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
[self setCellColor:[UIColor colorWithRed:0.192 green:0.192 blue:0.192 alpha:1] ForCell:cell]; //highlight colour
}
- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
[self setCellColor:[UIColor colorWithRed:0.239 green:0.239 blue:0.239 alpha:1] ForCell:cell]; //normal color
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
[self setCellColor:[UIColor colorWithRed:0.192 green:0.192 blue:0.192 alpha:1] ForCell:cell];
}
- (void)setCellColor:(UIColor *)color ForCell:(UITableViewCell *)cell {
cell.contentView.backgroundColor = color;
cell.backgroundColor = color;
//cell.backgroundView.backgroundColor = color;
}
I have already tried to change the selected cell border color in various ways, but all of them were not successful.
Can someone please help me to solve this problem.
source to share
You just need to set the "selection" property of the UITableViewCell to "none" and add the following code to the controller. see screenshot for work.
code:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
[self setCellColor:[UIColor colorWithRed:0.239 green:0.239 blue:0.239 alpha:1] ForCell:cell]; //normal color
}
source to share