How to remove UITableView separator (Xcode) - ios

In a prior Xcode versions, settings the separator style to none for the UITableView via the interface builder used to solve the problem.
But, this is no longer works in Xcode 7. How to remove/hide the UITableView Seperator in Xcode 7?

Xcode 7 is no longer picking the separator style from the interface
builder. This may also be related to the iOS 9 SDK as the Base SDK.
But, it always can be achieved programmatically:
// objective-c
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
// swift
tableview.separatorStyle = .None
Related, this is also applied on the UITableView background color:
// objective-c
[tableView setBackgroundColor:[UIColor clearColor]];
// swift
tableView.backgroundColor = .clear

In table init (viewDidLoad) you can adding this line:
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

Related

iOS 8: Remove Underline from UITableViewRowAction

I've been banging my head against the wall with this one, so maybe someone here has done this before.
Anyway, I'm trying to change how the delete button looks in my UITableView, and I've got it mostly figured out. I'm changing it by setting the background Color to a UIImage of what I actually want it to look like.
Apparently, though, a UITableViewRowAction has a faint grey line under it, and I can't figure out how to make this disappear. Any pointers would be greatly appreciated. There's a link to what I'm talking about here:
Thank you very much!
This is a separator line of UITableView. You can remove it by setting it's style as None.
Objective C:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Swift:
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
Initially separator line is not visible, because I think height of image or view added in cell is more than cell height.
And that's why while you swipe separator line is visible. If you are testing in Simulator than use Debug > Color Blended Layers of Simultor. Which is helpful to track overlapping views.
Edit:
iOS 8.0 introduced layoutMargins for UITableView. So it may be possible reason for that also.
Check out this answer for more information.
It explains to clear layout margins by setting cell layoutMargins as UIEdgeInsetsZero.
Try this on cellForRowAtIndexPath Method
for iOS lower versions
if(indexPath.row != self.newCarArray.count-1){
UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 44, 320, 2)];
line.backgroundColor = [UIColor redColor];
[cell addSubview:line];
}
for iOS 7 upper versions
if (indexPath.row == self.newCarArray.count-1) {
cell.separatorInset = UIEdgeInsetsMake(0.f, 0.f, 0.f, cell.bounds.size.width);
}

UITableView tableView cell separator is not showing in group style ios 7

I am having a problem in displaying cell separator of grouped style tableView in iOS 7.
if ([projectTable respondsToSelector:#selector(setSeparatorInset:)]) {
[projectTable setSeparatorInset:UIEdgeInsetsZero];
projectTable.separatorColor = [UIColor blackColor];
}
This doesn't show cell separator. Kindly suggest
In iOS7 design. try to do the below:
[projectTable setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
and also you have to do:
[projectTable setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
You can set the 'Separator Inset' from the nib or Storyboard:
Even though it has a default value (UITableViewCellSeparatorStyleSingleLine), have you tried reseting your separatorStyle property ?
[projectTable setSeparatorStyle:UITableViewCellSeparatorStyleSingleLineEtched];

Unwanted separator is showing on iOS 7

I am running my app on iOS 5, 6 and 7.
On iOS 5 and 6 my tableview doesn't have any separator, but when running app on iOS 7 separator is appearing between cells.
I used following code, but still the separator visible on iOS 7
if ([self.tableView respondsToSelector:#selector(setSeparatorStyle:)]) {
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}
Also, I used this code :
if ([tableView respondsToSelector:#selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
I put above code in ViewDidLoad method. But nothing work for me.
Is there any other way to hide/remove the separator in iOS 7.
Thanks,
Don't use your
if ([self.tableView respondsToSelector:#selector(setSeparatorStyle:)])
the property separatorStyle is available for all iOS.
#property(nonatomic) UITableViewCellSeparatorStyle separatorStyle; // default is UITableViewCellSeparatorStyleSingleLine
I use this in my code and work perfectly with iOS7 :
_table.separatorStyle = UITableViewCellSeparatorStyleNone;
Try to change the separator color to clear
Try setting the inset on the cells:
cell.separatorInset = UIEdgeInsetsMake(0, CGRectGetWidth(cell.bounds), 0, 0);

UITableViewStyleGrouped appears as plain in iOS 6

When using the iOS 6 SDK and running my app in the iPhone 5.0 simulator my tableview appears just fine as a grouped style tableview. However when I run my in the iPhone 6.0 simulator it appears as a UITableViewStylePlain tableview.
Any ideas what would cause this strange behavior? I'm not doing anything too crazy in the tableview besides a textview inside a tableview cell.
I have a grouped tableview that is working correctly in iOS6 using the code:
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.bounds.size.width,self.bounds.size.height) style:UITableViewStyleGrouped];
[tableView setDataSource:self];
[tableView setDelegate:self];
Are you using the Interface builder to create this grouped tableview or are you creating it programmatically? There seems to be quite a few issues with iOS6 and previously created interfacebuilder views.
If you are using the IB to create things can you try to re-create the tableview in code (redundant and useless, I know, but it may show what is the problem).
Somewhere in your viewDidLoad() function put
if(tableView)
{
[tableView removeFromSuperview];
}
tableView = [[UITableView alloc] initWithFrame:tableView.frame style:UITableViewStyleGrouped];
[tableView setDataSource:self];
[tableView setDelegate:self];
[self addSubview:tableView];
This may be poor coding or cause memory leaks if not using arc, but it would be interesting to see if you get a grouped styling that way.
This code solved the ios6 grouped tableview problem for me:
tableView.backgroundColor = [UIColor clearColor];
tableView.opaque = NO;
tableView.backgroundView = nil;

Why doesn't UITableViewCell background color work (set in interface builder)?

Why doesn't UITableViewCell background color work (set in interface builder)?
I note from some searching that the follow code set in your custom subclass of UITableViewController does work (see below):
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor redColor];
}
But I would still like to just understand why interface builder has a background color setting for the TableViewCell, which effectively doesn't seem to work?
It's a bit late, but I just ran into this issue... Setting the background color on the contentView works fine:
cell.contentView.backgroundColor = [UIColor redColor];
What worked for me is creating my own UIView object to be set as the background view of the UITableViewCell. In the cellForRowAtIndexPath:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIView* bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
bgview.opaque = YES;
bgview.backgroundColor = [UIColor orangeColor];
[cell setBackgroundView:bgview];
Trying to set the background colour of the UITableViewCell itself is not how you should be doing it. A table cell has a collection of five useful views you can access, one of which is backgroundView.
Recommended reading:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
and then:
http://cocoawithlove.com/2010/12/uitableview-construction-drawing-and.html
You should always provide changes for cells in tableView:willDisplayCell:forRowAtIndexPath: instead of the tableView:cellForRowAtIndexPath: method, as per Apple Documentation.
This Works !!
[cell.textLabel setBackgroundColor:[UIColor clearColor]];
[cell.contentView setBackgroundColor:[UIColor redColor]];
Make sure before defining a cell color your backgroundView is null
cell.backgroundView = nil;
cell.backgroundColor = [UIColor redColor];
This is simple and works: in interface builder, add a view object to the UITableViewCell of the same dimensions, and place your controls inside that view. Then you get whatever background color you want.
Edit: here's a reason to accept, it just struck me: take a careful look at what you get when you double click on a UITableViewCell in IB that you place into your nib, to start adding stuff to it: you don't get a plain rectangle looking view, you get an oval rectangle that says quite clearly: Content View. So all you can do is set the content view of the UITableViewCell in IB, and setting the background color property of the content view does not produce the color change in the table. As the docs say, UITableViewCells are complex beasts with many parts with a lot going on behind the scenes in terms of the UITableView adjusting it and fiddling with it.
It works perfectly, if you pick the tableview and set background to for example red the whole table will be red.
maybe you do not linked the table or something
hope it helped
(try this)
Apple's IB's design is generic to be applied to multiple kinds of components, and is also targeted at a highly technical audience (developers). Hence it has not been designed (as an application) to fully customise the interface properly for each component/situation type. So in this case it is the case the ability to seemingly set the background-color is somewhat misleading.
Y not, use setBackgroundColor
self.table.separatorColor=[UIColor whiteColor];
[table setBackgroundColor:[UIColor colorWithRed:.8 green:.8 blue:1 alpha:1]];
You can partially do this in Interface Builder (probably added to Xcode recently):
Expand the cell in the Storyboard's Document Outline and select "Content View"
Set Content View background color in the Attributes Inspector
Select each content item in the cell and set their background colors
to ClearColor
Still don't see a way to set the accessory background though.
I did get this issue also.
In IB you get the ability to change the background color of the cell when choosing cell. This is NOT correct. You should go to the document outline on the left of the storyboard and choose the content view inside the cell. Change the background of the content view. You should now get correct cell color.
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
UIView *view = [[UIView alloc] init];
[view setBackgroundColor:[UIColor redColor]];
[cell setSelectedBackgroundView:view];}
We need to change the color in this method.
Try this it works for me:
- (void)tableView:(UITableView *)tableView1 willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell setBackgroundColor:[UIColor clearColor]];
tableView1.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: #"Cream.jpg"]];
}

Resources