iphone - displaying email address and name from address book on tableview while text filed editing in ios -
i have application in have textfiled.just beneath text filed adding tableview.when starting typing letter in textfield searches address book , display name along email address of person on tableview.but problem not displaying emailaddress along name on tableview. code
-(void)textfielddidchange:(uitextfield *)txtfld { [self fetchaddressbook];
nsstring *dictionarykey = contact.name; nsstring *predicatestring = contact.email; //---get states beginning letter--- nspredicate *predicate = [nspredicate predicatewithformat:@"self beginswith[c] %@", contact.email]; listfiles = [nsmutablearray arraywitharray:[self.namearray filteredarrayusingpredicate:predicate]]; nssortdescriptor *sortdescriptor = [[nssortdescriptor alloc] initwithkey:@"name" ascending:yes] ; nsarray *sortdescriptors = [nsarray arraywithobject:sortdescriptor]; nsarray *sortedarray = [listfiles sortedarrayusingdescriptors:sortdescriptors]; if ([sortedarray count]>0) { tblview.hidden=false; txtsendamount.hidden=true; txtsendmessage.hidden=true; [tblview reloaddata]; } else if ([sortedarray count]==0) { tblview.hidden=true; txtsendamount.hidden=false; txtsendmessage.hidden=false; } }
//initially fetching contacts address book , using predicate on contacts array.
this code fetch address book
-(void)fetchaddressbook { cferrorref error = nil; abaddressbookref allpeople = abaddressbookcreatewithoptions(null,&error); cfarrayref allcontacts = abaddressbookcopyarrayofallpeople(allpeople); cfindex numberofcontacts = abaddressbookgetpersoncount(allpeople); nsmutablearray *testarray = [[nsmutablearray alloc] init]; nsmutabledictionary *addressdict = [[nsmutabledictionary alloc] init]; for(int = 0; < numberofcontacts; i++){ name = @""; nsstring* phone = @""; email = @""; contact = [[mcontact alloc] init]; abrecordref aperson = cfarraygetvalueatindex(allcontacts, i); abmultivalueref fnameproperty = abrecordcopyvalue(aperson, kabpersonfirstnameproperty); abmultivalueref lnameproperty = abrecordcopyvalue(aperson, kabpersonlastnameproperty); abmultivalueref phoneproperty = abrecordcopyvalue(aperson, kabpersonphoneproperty); abmultivalueref emailproperty = abrecordcopyvalue(aperson, kabpersonemailproperty); nsarray *emailarray = (__bridge nsarray *)abmultivaluecopyarrayofallvalues(emailproperty); nsarray *phonearray = (__bridge nsarray *)abmultivaluecopyarrayofallvalues(phoneproperty); if (fnameproperty != nil) { contact.name = [nsstring stringwithformat:@"%@", fnameproperty]; } if (lnameproperty != nil) { contact.name = [contact.name stringbyappendingstring:[nsstring stringwithformat:@" %@", lnameproperty]]; } if ([phonearray count] > 0) { if ([phonearray count] > 1) { (int = 0; < [phonearray count]; i++) { phone = [phone stringbyappendingstring:[nsstring stringwithformat:@"%@\n", [phonearray objectatindex:i]]]; } }else { phone = [nsstring stringwithformat:@"%@", [phonearray objectatindex:0]]; } } if ([emailarray count] > 0) { if ([emailarray count] > 1) { (int = 0; < [emailarray count]; i++) { contact.email = [contact.email stringbyappendingstring:[nsstring stringwithformat:@"%@\n", [emailarray objectatindex:i]]]; } }else { contact.email = [nsstring stringwithformat:@"%@", [emailarray objectatindex:0]]; } } [addressdict setobject:contact.email forkey:contact.name]; nslog(@"%@",addressdict); nslog(@"name : %@",name); nslog(@"phone: %@",phone); nslog(@"email: %@",email); [self.emailnamearray addobject:contact]; self.namearray = [emailnamearray copy]; nslog(@"namearray: %@",namearray); } }
//this cellforrowatindexpath method
-(uitableviewcell*)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tblview dequeuereusablecellwithidentifier:@"eventcell"]; if(!cell){ cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:@"eventcell"]; } mcontact *addressdict = [listfiles objectatindex:indexpath.row]; cell.textlabel.text=addressdict.name; cell.detailtextlabel.text=addressdict.email; return cell; }
please me in solving problem. thanks
first check whether contact having email address. problem 1) can't able email address 2) not able display saved email address
Comments
Post a Comment