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.

enter image description here

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.

+3


source to share


3 answers


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.

enter image description here



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
}

      

+1


source


try it. Select the tableview and go to the Attribute Inspector. In the separator, just set the table separator color to clear the color.



+2


source


Try it.

Select the tableview and go to the Attribute Inspector.

Find the property separator and make it the default "None".

And also set the color to "Clear Color".

I hope this works for you ... good luck !! :)

0


source







All Articles