ios - How to pass the in-place edited content back to the previous tableview controller (update the model) -


i have 2 table views, 1 called maintableviewcontroller (mtvc), other called detailtableviewcontroller (dtvc). it's typical click accessory button on main tableview cell bring detail tableview kinda thing.

in prepareforsegue method, data passed main tableview detail tableview nsmutablearray called item.

and how got displayed: cell.detailtextlabel.text = self.item[indexpath.row];

the cool thing managed in-place editing on detail table view cell (overwrote nstableviewcell, added uitextfield subview each cell).

everything works, last thing spent whole day cannot figure out how update nsmutablearray item after in-place editing taken place, ultimate goal in-place editing, , main tableview data shall reflect change.

i tried use delegation , protocol not work (the in-place edited content didn't got passed back, part of reason don't know how capture edited content, it's not it's text field name, can't updatedcontent = self.mytextfield.text grab change)

i'm running out of ideas, highly appreciated, thanks.

here's prepareforsegue in main tableview controller

    - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender     {         if ([segue.identifier isequaltostring:@"toinventorydetail"]) {              nsmutablearray *selecteditem = nil;              if (self.searchdisplaycontroller.active) {                 selecteditem = _searchresults[[sender row]];             } else {                 selecteditem = _appdelegate.items[[sender row]];             }              upfinventorydetailtableviewcontroller *idtvc = segue.destinationviewcontroller;             idtvc.item = selecteditem;         }     } 

and here's cellforrowatindex @ detail tableview controller

    - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath     {         static nsstring *cellidentifier = @"cell";          upfeditableuitableviewcell *cell = [[upfeditableuitableviewcell alloc] initwithstyle:uitableviewcellstylevalue2 reuseidentifier:cellidentifier];          cell.textlabel.text = _appdelegate.title[indexpath.row];         cell.detailtextlabel.text = self.item[indexpath.row];          [cell showeditingfield:yes];          return cell;     } 

i wrote delegation delete them after cause didn't work.

i had idea, still using delegation , protocol obviously: when 'done' button in detail tableview hit, go grab row contents , build new array, using delegation pass new array main tableview controller, add new array model meanwhile delete old one. tricky thing still how can grab contents in detail tableview?

update: haha! think solved half of puzzle !

here's solution detail tableview controller

    - (ibaction)doneupdate:(uibarbuttonitem *)sender {         [self.delegate additem:[self newitem]];     }      - (nsmutablearray *)saveitem     {         nsmutablearray *newitem = [[nsmutablearray alloc] init];         nsarray *indexpathes = [self.tableview indexpathsforvisiblerows];         (nsindexpath *indexpath in indexpathes) {                 upfeditableuitableviewcell *cell = (upfeditableuitableviewcell *)[self.tableview cellforrowatindexpath:indexpath];         [newitem addobject:cell.editfield.text];         }         return newitem;     } 

and here's main tableview controller

    - (void)additem:(nsarray *)item     {         //take updated item insert items array new item         [_appdelegate.items addobject:item];         //remove selected item (the 1 being updated) items array         [_appdelegate.items removeobject:_appdelegate.selecteditem];         [self.tableview reloaddata];         [self.navigationcontroller popviewcontrolleranimated:yes];     } 

when creating cell - give tags your uitextfields can collect data entered delegate methods - can either make nsdictionary/ key value pairs or can add nsarray.

- (void)textfielddidendediting:(uitextfield *)textfield {         if(textfield.tag == 11) {            // can add desired array/dictionary        }    }  or  - (bool)textfieldshouldreturn:(uitextfield *)textfield {   if(textfield.tag == 11) {            // can add desired array/dictionary        }   } 

you can use delegation/protocol or store values in nsuserdefault , on mainviewcontroller.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -