You can just add a UIView
with the same background color as you want your separator line to be at the top of your UITableViewCell
layout, make its height one pixel (it will be the same as a line) and its width the same as your cell width (cell.frame.size.width). After this in your cellForRowAtIndexPath
just set hidden
property of this to YES
for the cell you don't want it to be shown and hidden
= NO
for those you want. It is a simple solution which will work in any iOS version. But if will add your custom separator don't forget to disable default separators for all tableview
uitableviewCell Separator line
-
29-06-2023 - |
Question
Hi I'm new to ios development. I am developing an application in which I am using UITableView
.
Tableview
contains some cells with separator line and others without separator line.
Can any one please tell me how can I remove separator line for specific cell?
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, cell.bounds.size.width);
Above code works for iOS 7
. How can I achieve this in iOS6
?
Any help is appreciated
Solution
OTHER TIPS
In order to have only specific cells with separator you have to draw separator lines for those cells. In my view set the separator style to none and then draw you custom separator for the desired cells.
You can follow this link for custom separators Basically what u need to do is add a custom view as follows:
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];/// change size as you need.
separatorLineView.backgroundColor = [UIColor grayColor];// you can also put image here
[cell.contentView addSubview:separatorLineView];
to set the separator style to none use:
tableView.separatorStyle=UITableViewCellSeparatorStyleNone
If you try to change the color of the separatorLine for this. But one thing is that if you want to make the adjacent cells as a single cell then this would not be the right approach. As this will make only the UI change.
The better approach would be to adjust the size of the cell and so that you get "single cellClick events for them".
you can use the delegate for this:-
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;