ios - how prevent cell width from expanding when done editing in UITableView -


if notice in ipad contacts app when tap on "+" edit icon add new address, cell not expand left when icon disappears (see 1st screen capture below). trying similar having no luck (see 2nd screen capture below). tried using solution suggested here didn't work.

for record not trying replicate actual contacts app or integrate contacts. we're working on unrelated , designer wants follow pattern doing poc work see can do.

edit - question, verify thinking, in contacts app here what's happening when "+" icon tapped, cell set not editing more, these text fields added cell, label changed, , reloaddata called, right?

edit - suggestion tim, i'm there! had worked out 1/2 of running issue "+" icon not animating out, abruptly disappearing. added reloadrows... call commiteditingstyle entire cell disappears. here code:

- (uitableviewcelleditingstyle)tableview:(uitableview *)tableview editingstyleforrowatindexpath:(nsindexpath *)indexpath  {     uitableviewcelleditingstyle editingstyle = uitableviewcelleditingstylenone;     if (self.showeditingicon) {         editingstyle = uitableviewcelleditingstyleinsert;         self.showeditingicon = no;     }     return editingstyle; }  - (void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath {     //    tableview.editing = no;     //    tableview.editing = yes;     [self.tableview reloadrowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationfade]; } 

you can see commented-out lines had originally, working said, not animating - "+" button abruptly disappearing. if tried call [tableview setediting:no animated:yes] not work. when tried put these calls within uiview animation block did not - see cell temporarily shift left , back. reload call cell disappears completely. @ moment i'm not making changes cell (for example i'm not adding text fields, etc...) because want make "+" button animating out without making cell expand left work on first iteration.

any appreciated. thanks.

enter image description here enter image description here

the trick in editing mode such cell indention remains constant. when cell loaded, decide state in , return appropriate editing style, either "insert" style or "none":

- (uitableviewcelleditingstyle)tableview:(uitableview *)tableview editingstyleforrowatindexpath:(nsindexpath *)indexpath {     bool shouldshowinsertbutton = ...;//check internal state cell     return shouldshowinsertbutton ? uitableviewcelleditingstyleinsert : uitableviewcelleditingstylenone; } 

then when edit button tapped, update internal state , reload cell:

- (void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath {     ...;//update internal state cell     [self.tableview reloadrowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationfade]; } 

edit

here's working sample project.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -