objective c - Insert row in UiTableView does not update rest cell’s indexPath? -


say i’m loading uitableview each uitextview inside each cell subview.and i’ve assigned indexpath.row tags each textview.

-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *cellidentifier = @"userdetails";     uitableviewcell *cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];     uitextview *textview=[[uitextview alloc]initwithframe:cgrectmake(0, 0, self.frame.size.width, 60)];     nsstring * mystring = [contentarray1 objectatindex:indexpath.row];     textview.text= mystring;      uitapgesturerecognizer *taprecognizer = [[uitapgesturerecognizer alloc]     [taprecognizer setnumberoftouchesrequired:1];     [taprecognizer setdelegate:self];     textview.userinteractionenabled = yes;     textview.tag = indexpath.row;//assign tags textview     [textview addgesturerecognizer:taprecognizer];     [cell addsubview:textview];      return cell; } 

below method gets called once user taps on textview.i’m seeing proper tag values printed when tap on textviews.

-(void) action:(id)sender {     //nslog(@"testing tap");     uitapgesturerecognizer *taprecognizer = (uitapgesturerecognizer *)sender;      nslog (@"%d",[taprecognizer.view tag]); } 

now insert row in tableview,say @ index 3.

what did simple,

[contentarray1 insertobject:[nsstring stringwithformat:@"added cell”] atindex:3]; nsindexpath *indexpath = [nsindexpath indexpathforrow:3 insection:0]; [self.tableview insertrowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationautomatic]; 

now when try tap on textviews after inserted cell,i’m able see old tag values.meaning,after row gets inserted tableview @ index=3,when tap on textview can see tag=2,then again when tap on next cell’s textview can see tag=2,it should 3.

my question is,once insert row/cell in tableview,the tableview not refresh other cell tags/index?….

i can fix calling reloadvisiblecells method.but i’m looking out better solution.i don’t want refresh whole screen inserting row.any solutions appreciated.

try this:

[self.tableview beginupdates]; [self.tableview insertrowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationautomatic]; [self.tableview endupdates]; 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -