开发者

how to search contact from address book using uitextview in iphone?

开发者 https://www.devze.com 2023-02-16 14:28 出处:网络
i\'m using uitextview for searching the contact details from address book. i.e., like uisearchbar search the contact details while tex开发者_运维问答t edit change in uitextview.

i'm using uitextview for searching the contact details from address book. i.e., like uisearchbar search the contact details while tex开发者_运维问答t edit change in uitextview.

how to search contact from address book using uitextview in iphone?

i'm using uitextview if i tap 'a', the list of the contacts from address book will be display in table view

please give me the solution


Finally I got the solution simple coding here it is

//viewDidLoad

  NSMutableArray *personArray = [[NSMutableArray alloc] init];
  ABRecordRef personRef;
  for (int i = 0; i < CFArrayGetCount(allPeople); i++)
  {
    personRef = (ABRecordID*)CFArrayGetValueAtIndex(allPeople, i);
    ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, ABRecordGetRecordID(personRef));
    @try 
    {
        if (ABRecordCopyValue(person, kABPersonBirthdayProperty))
            [personArray addObject: (id)personRef];
    }
    @catch (NSException * e) 
    {
    }
    @finally 
    {
    }
  NSString *FirstName = [[[NSString stringWithString:(NSString *)ABRecordCopyValue(personRef, kABPersonFirstNameProperty)]stringByAppendingString:@" "]stringByAppendingString:(NSString *)ABRecordCopyValue(personRef, kABPersonLastNameProperty)];
    [arr addObject:FirstName];
}
[arr3 addObjectsFromArray:arr];
  }

//textviewdidchange

  [arr3 removeAllObjects];
   NSInteger counter = 0;
  for(NSString *name in arr)
  {
    NSRange r = [name rangeOfString:txtView.text options:NSCaseInsensitiveSearch];  
    if(r.location != NSNotFound)
    {
         [arr3 addObject:name];
    }
    counter++;
}
[table reloadData];

Thanks for your help

0

精彩评论

暂无评论...
验证码 换一张
取 消