objective c - Add edit functionality in contacts in iOS using Addressbook -


i'm trying create simple create, display , edit contacts in xcode 4.2 ios using addressbook, far have done create , display function. need implement edit function along display. when click on display displays contacts , when click on name shows info button , cancel button. need change cancel button edit , call edit functionality. below code of viewcontroller.m have done far. appreciate if u give me solution.

#import "viewcontroller.h" #import <addressbook/addressbook.h> enum mainmenuchoice {     menudisplaycontacts,     menucreatecontacts  };  @implementation viewcontroller  @synthesize menuarray;  - (void)viewdidload {     [super viewdidload];      nsstring *plistpath = [[nsbundle mainbundle] pathforresource:@"menu" oftype:@"plist"];      nslog(@"%@",plistpath);     self.menuarray = [nsmutablearray arraywithcontentsoffile:plistpath]; }  - (void)viewdidunload {      self.menuarray = nil;    }  #pragma mark table view methods - (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     return [menuarray count]; }   // customize number of rows in table view. - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return 1; } // customize appearance of table view cells. - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *cellidentifier = @"cell";     uitableviewcell *acell = [tableview dequeuereusablecellwithidentifier:cellidentifier];     if (acell == nil) {          // make rows buttons            acell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];           acell.textlabel.textalignment = uitextalignmentcenter;      }      acell.textlabel.text = [[menuarray objectatindex:indexpath.section] valueforkey:@"title"];      return acell; }  - (void) tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     switch (indexpath.section) {         case menudisplaycontacts:              [self showcontacts];             break;          case menucreatecontacts:             [self createcontacts];             break;          default:             [self showcontacts];             break;     } }   //show list of people in contacts - (void)showcontacts {     abpeoplepickernavigationcontroller *picker = [[abpeoplepickernavigationcontroller alloc]init];     picker.peoplepickerdelegate = self;     nsarray *displayitems = [nsarray arraywithobjects:[nsnumber numberwithint:kabpersonphoneproperty],[nsnumber numberwithint:kabpersonemailproperty], [nsnumber numberwithint:kabpersonbirthdayproperty],nil];      picker.displayedproperties = displayitems;      [self presentmodalviewcontroller:picker animated:yes];  }  // dismisses people picker , shows application when users tap cancel.  -(void)peoplepickernavigationcontrollerdidcancel:(abpeoplepickernavigationcontroller *)peoplepicker {     [self dismissmodalviewcontrolleranimated:yes]; }  //for creating new contact when user tap create contacts -(void)createcontacts {      abnewpersonviewcontroller *picker = [[abnewpersonviewcontroller alloc]init];     picker.newpersonviewdelegate=self;      uinavigationcontroller *navigation = [[uinavigationcontroller alloc] initwithrootviewcontroller:picker];     [self presentmodalviewcontroller:navigation animated:yes];  }  // dismisses new-person view controller when user tap cancel.  - (void)newpersonviewcontroller:(abnewpersonviewcontroller *)newpersonviewcontroller didcompletewithnewperson:(abrecordref)person {     [self dismissmodalviewcontrolleranimated:yes]; }  @end 

i can desired result if code in tableview didselectrowatindexpath property, want implement , integrate code inside displaycontacts method instead of tableview here. because method initial screen display , create contacts. there other way indexpath of current selected names once inside display contacts???

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {      abpersonviewcontroller *dvc=[[abpersonviewcontroller alloc]init];      abaddressbookref addressbook = abaddressbookcreatewithoptions(null,null);     nsmutablearray *allpeople = (__bridge nsmutablearray *)abaddressbookcopyarrayofallpeople(addressbook);     int npeople = abaddressbookgetpersoncount(addressbook);     for(int i=0;i<npeople;i++) {          abrecordref person = (__bridge abrecordref)([allpeople objectatindex:i]);         nsstring *name = [self.contactadd objectatindex:indexpath.row],*name2;         if(abrecordcopyvalue(person, kabpersonfirstnameproperty) != null) {             name2 = [[nsstring stringwithformat:@"%@", abrecordcopyvalue(person, kabpersonfirstnameproperty)]                      stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset]];             name2=[name2 stringbyappendingstring:@" "];             name2=[name2 stringbyappendingstring:[[nsstring stringwithformat:@"%@", abrecordcopyvalue(person, kabpersonlastnameproperty)]                                                   stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset]]];         }         if([name isequaltostring:name2])             {                 dvc.displayedperson=person;                 dvc.allowsediting=yes;                 [self.navigationcontroller pushviewcontroller:dvc animated:yes];                 break;             }     }  } 

-(bool)peoplepickernavigationcontroller: (abpeoplepickernavigationcontroller *)peoplepicker shouldcontinueafterselectingperson:(abrecordref)person {              [peoplepicker dismissmodalviewcontrolleranimated:no];              abpersonviewcontroller *picker = [[abpersonviewcontroller alloc] init];             picker.personviewdelegate = self;             picker.displayedperson = person;             // allow users edit person’s information             picker.allowsediting = yes;             [self.navigationcontroller pushviewcontroller:picker animated:yes];        return yes; } 

got solution of function, stuck in adding delete function :p


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -