I am using xcode6.0.1.In my UIVIew Controller contains one tableview and i need to set separator inset full width.I changed my tableview separator inset via xib.But i can’t get full width for separator inset on my xcode6 (In my xcode5 separator inset full width is possible).How to solve this issue?
change tableview separator inset via xib
my tableview separator line like this(not get full width)
I solved my issue
-(void)viewDidLoad{
self.tableView.layoutMargins = UIEdgeInsetsZero;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([cell respondsToSelector:#selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
Use this method in iOS 8 [tableView setLayoutMargins:UIEdgeInsetsZero];
I guess you simulated your app in iOS8 , this is a new property "#property(nonatomic) UIEdgeInsets layoutMargins " in iOS8. I suggest you try to create a UITableViewCell class category(e.g. UITableViewCell+Separator) then add this getter
- (UIEdgeInsets)layoutMargins
{
return UIEdgeInsetsZero;
}
in iOS7 this will not be called cos there's no this property in SDK,and will not cause any crash; in iOS8 this will be called every time you use the cell
It works for me
I found a weird white space on UITableView for iPhone 6 Simulator (iOS 8) on Xcode 6 GM. I have tried to set the SeparatorInset from both storyboard and also the code, but the white space is till there.
The following code works on iOS 7 but not on iOS 8 (iPhone 6 simulator).
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([tableView respondsToSelector:#selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
}
I attached screenshot below:
I am using AutoLayout by the way. I hope someone can show me a way to remove the weird white space on the TableView.
Thanks Student for pointing me to the right direction with the comment "Try this self.myTableView.layoutMargins = UIEdgeInsetsZero;" This line of code will only work on iOS 8 because layoutMargins is only available from iOS 8. If I run the same code on iOS 7, it will crash.
#property(nonatomic) UIEdgeInsets layoutMargins
Description The default spacing to use when laying out content in the view.
Availability iOS (8.0 and later)
Declared In UIView.h
Reference UIView Class Reference
Below is the right answer to solve this weird white space by setting the tableview layoutMargins and cell layoutMargins as UIEdgeInsetsZero if it exists (for iOS 8). And it will not crash on iOS 7 as well.
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([tableView respondsToSelector:#selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([tableView respondsToSelector:#selector(setLayoutMargins:)]) {
[tableView setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:#selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
See the screen shot below:-
Try to create a UITableViewCell class category and add this getter
- (UIEdgeInsets)layoutMargins {
return UIEdgeInsetsZero;
}
in iOS7 this will not be called cos there's no this property in SDK,and will not cause any crash;
in iOS8 this will be called every time you use the cell
It works for me
My solution with just three lines of code:
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)row{
//
// ... your code ...
//
if ([cell respondsToSelector:#selector(preservesSuperviewLayoutMargins)]){
cell.layoutMargins = UIEdgeInsetsZero;
cell.preservesSuperviewLayoutMargins = false;
}
return cell;
}
IOS8 introduce a new concept named Configuring Content Margins , a new property named layoutMargins is also introduced , for the details of the property , please refer to the Apple Doc . The type of layoutMargins is UIEdgeInsets , by default the value is {8,8,8,8} . To remove the seperator line of TableView in IOS8 , in addition to set tableView.seperatorInset = UIEdgeInsetsZero , you must also do as :
First define the macro
#define isIOS8SystemVersion (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
In the UITableViewDelegate method add :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuseId = #"cellReuseID" ;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
if(!cell){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseId];
if(isIOS8SystemVersion){
cell.layoutMargins = UIEdgeInsetsZero;
cell.preservesSuperviewLayoutMargins =NO ;
}
}
Doing these will remove the seperator line . You can also do as follow :
UITableView *tableView = [[UITableView alloc] init];
if(isIOS8SystemVersion){
tableView.layoutMargins = UIEdgeInsetsZero ;
}
and in the UITableViewDelegate method add :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuseId = #"cellReuseID" ;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
if(!cell){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseId];
if(isIOS8SystemVersion){
cell.layoutMargins = UIEdgeInsetsZero;
}
}
In my case in Xcode 6.2, in addition to Will Q's answer, I have to go to Main.storyboard > select the UITableViewCell > Attributes Inspector. Change Separator dropdown list from Default Insets to Custom Insets. Change the left inset from 15 to 0.
Workaround for iOS 7 & iOS 8
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.separatorInset = UIEdgeInsetsMake(0.0f, cell.frame.size.width, 0.0f, 0.0f);
}
In iOS8 you have to set the Inset both on Row and on Table level.
Row level in the cellForRowAtIndexPath:
if ([cell respondsToSelector:#selector(preservesSuperviewLayoutMargins)]){
cell.layoutMargins = UIEdgeInsetsZero;
cell.preservesSuperviewLayoutMargins = false;
}
Table level in the viewDidLoad:
[tableReference setSeparatorInset:UIEdgeInsetsZero];
After that it is a good idea to CLEAN your project. On some occasions I noted that these changes were not directly introduced in the executable App in the simulator.
for iOS 8
try by setting cell.layoutMargins = UIEdgeInsetsZero; in cellForRowAtIndexPath method
If you want to remove the white line, but keep separator inset as it is, just set the cell.backgroundColor to the tableView backgroundColor. Just setting the cell.contentView.backgroundColor does not make the problem disappear.
I've tried many ways, none of them work but this one works for me.
Add startup images for iPhone 6 and Plus. Before the images are added the phone is running in scaling mode, i.e. older Apps get scaled to fit the new screen sizes. This may be causing the lines.
The new images are Retina HD 5.5 (iPhone6Plus) 1242x2208 and Retina HD 4.7 (iPhone6) 750x1334.
See iOS 8 UITableView separator inset 0 not working
Basically, you need to set both the cell.layoutMargin as well as the tableView's layoutMargin. YMMV, but I had to set the table view up in layoutSubviews before it would work!
To make your UITableView separator insets to zero for both iOS7 and iOS8, instead of making a change in the code, make a change in the xib for the UITableView by changing the View->Mode->Aspect Fill.
I have static UITableView and wanted to shift the margin of a cell separator to the left edge.
Thanks to the above answers, this was my solution
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
// needed to shift the margin a specific cell to the left edge
if indexPath.section == 3 && indexPath.row == 0 {
cell.layoutMargins = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
cell.separatorInset = UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0)
}
}
Just add the following:
tableView.separatorStyle = .none
How do you set the separatorInsets of a table view cell back to their default values programmatically? I want to change them for some cells but not others.
Use following way :
if (indexPath.row == {your row number}){
cell.separatorInset = UIEdgeInsetsMake(0, 15, 0, 0);
}
In iOS7 table view has default 15 left inset for separator,you can change it as per your requirement by using above code.
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
According to documentation,
UITableViewCellSeparatorStyleSingleLine
The separator cell has a single line running across its width. This is the default value. Available in iOS 2.0 and later.
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];
I am checking my app with ios 7 beta. I have set background color of UITableView to clear color. Its still showing white background.
Is there any other way around to make it transparant?
I couldn't make it work but the following worked perfectly :
-(void)tableView:(UITableView *)tableView
willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell setBackgroundColor:[UIColor clearColor]];
}
Setting tableview backgroundColor to clear color working absolutely fine in iOS 7 chk screenshot see those separator lines for the table cells while the tableview is transparent.
Believe it or not, the following statement, added to cellForRowAtIndexPath, will cause iOS 7 to honor the XIB-specified color:
cell.backgroundColor = cell.backgroundColor;
In my XCode 5 Storyboard I had to set the background color of the 'View' section on the Table View properties to clear as well.