2

我们如何自定义 ABPeoplePickerNavigationViewController 在第一行显示全名,在下一行显示电子邮件、电话号码。这不应该发生在联系人选择上,但应该在加载 ABPickerController 视图时默认发生。

我想要的是 ABPeoplePicker 的常规功能。但联系人显示应该有上面解释的附加信息。

我想我必须扩展 ABPeoplePickerNavigationController?对此有任何指导将不胜感激?

4

2 回答 2

1
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
// assigning control back to the main controller
[self dismissModalViewControllerAnimated:YES];
}

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
NSString *firstname=(NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
Usernametf.text=firstname;
 ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty);
NSArray *address = (NSArray *)ABMultiValueCopyArrayOfAllValues(addressProperty);

      NSString* phone;
     phone = (NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
     phoneNotf.text=phone;
     //NSLog(@"%@",phone);

if([address count] > 0)
{
    for (NSDictionary *addressDict in address)
    {
      NSString*  countrytf = [addressDict objectForKey:@"Country"];
      NSString*  streetaddresstf= [addressDict objectForKey:@"Street"];
      NSString*  citynametf = [addressDict objectForKey:@"City"];
      NSString*  statenametf = [addressDict objectForKey:@"State"];
       NSString* zipcodetf = [addressDict objectForKey:@"ZIP"];
    }
    CFRelease(addressProperty);
}

  //  NSMutableDictionary *dict=[[NSMutableDictionary alloc] initWithObjectsAndKeys:firstname,@"FirstName", nil];
//[selectedemailArray addObject:dict];
// NSLog(@"\n array is %@",selectedemailArray);


//[objDatabase insertArray:selectedemailArray forTable:@"EmailList"];
//[objDatabase insertDictionary:dict forTable:@"EmailList"];
 //    [dict release];
  //    dict =nil;

// remove the controller
[self dismissModalViewControllerAnimated:YES];
return NO;

 }

 - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
return NO;
 }

这是完整的代码,您可以从联系人那里获得任何信息。

让我知道它是否有效...

快乐编码!!!!

于 2012-12-14T06:24:23.137 回答
1

如果您希望 ABPeoplePicker.... 和 addressBook 一起工作,则没有解决方案。尝试了同样的事情,但最后我们推出了一个新的自定义索引表视图。很容易。如果你想创建一个索引表视图,请查看 indexed-ui-tableview

然后,您可以更改以下方法以在多行中获取信息。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
                                   reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [[[content objectAtIndex:indexPath.section] objectForKey:@"rowValues"] 
                       objectAtIndex:indexPath.row];
cell.detailTextLabel.text=[NSString stringWithFormat:@"%@ %@ %@", @"someone@gmail.com", @"|",@"123456777777777777777"] ;;

return cell;

}

可以修改数据生成器以适应您的模型。电子邮件等可以从您的模型中获取。在上面的代码片段中,它是硬编码的。然后您可以轻松地连接搜索功能。

于 2012-12-19T13:26:28.917 回答