Q:

UITableView Separator line disappears when cell is inserted at first position and bottom cell is selected

I have code as follows:
#import "TestTableViewController.h"

@interface TestTableViewController ()
@property (nonatomic,strong) NSMutableArray *testDataArray;
@end

@implementation TestTableViewController

- (void)viewDidLoad
{
  [super viewDidLoad];
  self.testDataArray = [[NSMutableArray alloc] init];
  for(int i = 0; i < 20; i++){
    [self.testDataArray addObject:[NSString stringWithFormat:@"TestString - %@",@(i)]];
  }
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  return self.testDataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"testCell" forIndexPath:indexPath];
  cell.textLabel.text = [self.testDataArray objectAtIndex:indexPath.row];
  return cell;
}

- (IBAction)insertNewElement:(UIBarButtonItem *)sender
{
  [self.testDataArray insertObject:@"AAAAAA" atIndex:0];
  [self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:0 inSection:0]]
                        withRowAnimation:UITableViewRowAnimationAutomatic];
}

As you see code is very simple.
Storyboard is also standard:

But when I select third cell and insert new cell this happen (Newly inserted cell is without separator line):

I found one solution, but there is a problem with it.First it uses Private API, and second I'm not sure that this is good practice to do:
- (void)layoutSubviews {
  [super layoutSubviews];

  for (UIView *subview in self.contentView.superview.subviews) {
    if ([NSStringFromClass(subview.class) hasSuffix:@"SeparatorView"]) {
      subview.hidden = NO;
    }
  }
}

Is it possible, that this is bug in Apple?

A:

I would suggest to make little bit change in you simplified version of application with method implementation like, 
- (IBAction)insertNewElement:(UIBarButtonItem *)sender
{
    //Update 1:
    [self.tableView deselectRowAtIndexPath:[NSIndexPath indexPathForRow:selectedrow inSection:0] animated:NO];
    [self.testDataArray insertObject:@"AAAAAA" atIndex:0];
    [self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:0 inSection:0]]
                      withRowAnimation:UITableViewRowAnimationAutomatic];
    [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:selectedrow+1 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
} //selectedrow define in your .m file as NSInteger.

May this help you!!

