Remove SeparatorInset on iOS 8 UITableView for Xcode 6 iPhone Simulator

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:-

Remove SeparatorInset on iOS 8 UITableView for XCode 6 iPhone , 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 � Encontré un espacio en blanco extraño en UITableView para iPhone 6 Simulator (iOS 8) en XCode 6 GM. Intenté establecer SeparatorInset tanto en el guión gráfico como en el código, pero el espacio en blanco está ahí. El siguiente código funciona en iOS 7 pero no en iOS 8 (simulador de iPhone 6).

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

UITableview SepartorInset full width issue on my xcode6, 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 � This works perfectly in iOS 7.x, however in iOS 8.0 I see that the separator inset is set to the default of 15 on the right. Even though in the xib files it set to Add menu

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

objective c - iOS 8 UITableView separator inset 0 not working, Remove SeparatorInset on iOS 8 UITableView for XCode 6 iPhone Simulator. I found a weird white space on UITableView for iPhone 6 Simulator (iOS 8) on� I believe this is the same question that I asked here: Remove SeparatorInset on iOS 8 UITableView for XCode 6 iPhone Simulator. In iOS 8, there is one new property for all the objects inherit from UIView. So, the solution to set the SeparatorInset in iOS 7.x will not be able to remove the white space you see on the UITableView in iOS 8.

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

在Xcode 6 iPhone Simulator的iOS 8 UITableView上删除 , I believe this is the same question that I asked here: Remove SeparatorInset on iOS 8 UITableView for XCode 6 iPhone Simulator. In iOS 8, there is one new� func tableView (_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {//Remove seperator inset if cell. responds (to: #selector(setter: UITableViewCell.separatorInset)) {cell. separatorInset =. zero } //Prevent the cell from inheriting the Table View's margin settings if cell. responds (to: #selector(setter: UITableViewCell.preservesSuperviewLayoutMargins)) {cell. preservesSuperviewLayoutMargins = false} //Explictly set your cell's layout margins if

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.

在Xcode 6 iPhone Simulator的iOS 8 UITableView上删除 , 在Xcode 6 iPhone Simulator的iOS 8 UITableView上删除SeparatorInset I have tried to set the SeparatorInset from both storyboard and also the code, I hope someone can show me a way to remove the weird white space� 77 Get Location Updates for iOS App Even when Suspended Jan 2 '15 61 Remove SeparatorInset on iOS 8 UITableView for Xcode 6 iPhone Simulator Sep 10 '14 58 iOS 8 UITableView separator inset 0 not working Sep 11 '14

iOS 8 UITableView separator inset 0 not working, Remove SeparatorInset on iOS 8 UITableView for Xcode 6 iPhone Simulator我在Xcode 6 GM上的iPhone 6 Simulator(iOS 8)的UITableView上� je crois que c'est la même question que j'ai posée ici: supprimer le séparateur sur iOS 8 UITableView pour Xcode 6 iPhone simulateur . In iOS 8 , il y a une nouvelle propriété pour tous les objets hérités de UIView. Donc, la solution pour mettre le SeparatorInset dans iOS 7.x ne pourra pas supprimer l'espace blanc que vous voyez sur la

iOS 8 UITableView separator inset 0 not working-第2页回答- 码农岛, func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, Remove SeparatorInset on iOS 8 UITableView for XCode 6 iPhone Simulator. now problem is everything works well in Xcode 5 and SDK 7.1 , but after i opened my project. in Xcode 6 and SDK 8.1 the program runs well on iPhone 4,5,6 simulator (sdks 7.1 and 8.1) , but not working on real device. and fun part is one of buttons working and not the other . one.

separatorInset, I have an app where the UITableView 's separator inset is set to custom values Remove SeparatorInset on iOS 8 UITableView for XCode 6 iPhone Simulator.

Comments
  • I got a working reference from this blog datacalculation.blogspot.in/2014/10/…
  • See my answer in iOS 8 UITableView separator inset 0 not working
  • This answer may help others with the same issues: stackoverflow.com/a/38206546/1137246
  • Thanks for making this compatible with iOS7 as well. Works great on iOS8
  • I found, to get this to work for iOS 8, I had to reload the table view in ViewDidAppear.
  • I got a working reference from this blog datacalculation.blogspot.in/2014/10/…
  • Works. I'd be really interested if there's a solution using appearance and rip this code out of the table implementation
  • This worked great for me. This is all you need to add if you have custom cells.
  • This was the only solution that worked for when I implemented custom cells.
  • This one really needs more upvotes. Works perfectly in my case.
  • Simple, elegant and global solution! There is no need to add tha layoutMargin settings to each UITableView through entire project - just add a category and all will be ok. Thanks!
  • for me, cell.preservesSuperviewLayoutMargins = NO; is the key.
  • This should be the correct answer. Short and sweet! :) Works 100%