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


i have code 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 = 0; < 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 see code simple. storyboard standard:

enter image description here

but when select third cell , insert new cell happen (newly inserted cell without separator line):

enter image description here

i found 1 solution, there problem it.first uses private api, , second i'm not sure practice do:

- (void)layoutsubviews {   [super layoutsubviews];    (uiview *subview in self.contentview.superview.subviews) {     if ([nsstringfromclass(subview.class) hassuffix:@"separatorview"]) {       subview.hidden = no;     }   } } 

is possible, bug in apple?

i suggest make little bit change in simplified version of application 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 .m file nsinteger. 

may you!!


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -