在IOS中的UITableView中选择单元格时,表格单元格边框变得可见

时间:2015-06-19 04:42:12

标签: ios objective-c uitableview

我为我目前正在开发的ios应用程序实现了一个侧出菜单。我使用UITableViewController作为我的菜单,我想突出显示所选的菜单项。我已经完成了突出显示的事情,问题是当我选择其中一个菜单项时,表格单元格的上下边界变得可见。

这是我的侧边菜单,查看选定的表格单元格(菜单项)。有上下细胞边界或类似的东西。

enter image description here

这是我用来突出显示所选单元格的代码

- (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;


}

我已经尝试以不同的方式更改所选的单元格边框颜色,但所有这些都没有成功 有人可以帮我解决这个问题。

3 个答案:

答案 0 :(得分:2)

试试这个。 选择tableview并转到Attribute Inspector。 在分隔符中,只需将表视图分隔符颜色设置为清除颜色。

答案 1 :(得分:1)

您只需将UITableViewCell的“selection”属性设置为“none”,并将以下代码添加到控制器中。看截图它的工作。

enter image description here

代码:

- (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
}

答案 2 :(得分:0)

试试这个。

选择tableview并转到Attribute Inspector。

找到属性Separator并将其设置为Default to None。

并将颜色设置为“清除颜色”。

我希望它对你有用......祝你好运! :)