将所有人员以数组形式添加到 ABRecordRef 中

发布于 2024-11-09 08:40:34 字数 1658 浏览 0 评论 0原文

我如何将联系人中的人员添加到“人员”数组,然后添加到 abrecordref。???实际上我想要表视图中的所有联系人并且能够编辑单个记录。这是我的代码:

-(void)showPersonViewController
{      
    // Fetch the address book 
        ABAddressBookRef addressBook = ABAddressBookCreate();
        // Search for the person named "rubal" in the address book
        NSArray *people = (NSArray *)ABAddressBookCopyPeopleWithName(addressBook, CFSTR("naina"));
        // Display "KETAN" information if found in the address book 
        if ((people != nil) && [people count])
        {
            ABRecordRef person = (ABRecordRef)[people objectAtIndex:0];
            ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease];
            picker.personViewDelegate = self;
            picker.displayedPerson = person;
            // Allow users to edit the person’s information

            picker.allowsEditing = YES;
            [self.navigationController pushViewController:picker animated:YES];
        }
        else 
        {
            // Show an alert if "KETAN" is not in Contacts
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                                      message:@"Could not find naina in the Contacts application" 
                                                      delegate:nil 
                                                  cancelButtonTitle:@"Cancel" 
                                              otherButtonTitles:nil];
            [alert show];
            [alert release];
         }
           [people release];
           CFRelease(addressBook);
}

我希望表视图中的所有记录并单独编辑,而不仅仅是“naina”

how can i add the people from the contacts to 'people'- array then to abrecordref.??? Actually i want all the contacts in tableview and can able to edit individual record. here is my code:

-(void)showPersonViewController
{      
    // Fetch the address book 
        ABAddressBookRef addressBook = ABAddressBookCreate();
        // Search for the person named "rubal" in the address book
        NSArray *people = (NSArray *)ABAddressBookCopyPeopleWithName(addressBook, CFSTR("naina"));
        // Display "KETAN" information if found in the address book 
        if ((people != nil) && [people count])
        {
            ABRecordRef person = (ABRecordRef)[people objectAtIndex:0];
            ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease];
            picker.personViewDelegate = self;
            picker.displayedPerson = person;
            // Allow users to edit the person’s information

            picker.allowsEditing = YES;
            [self.navigationController pushViewController:picker animated:YES];
        }
        else 
        {
            // Show an alert if "KETAN" is not in Contacts
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                                      message:@"Could not find naina in the Contacts application" 
                                                      delegate:nil 
                                                  cancelButtonTitle:@"Cancel" 
                                              otherButtonTitles:nil];
            [alert show];
            [alert release];
         }
           [people release];
           CFRelease(addressBook);
}

instead of only 'naina' i want all record in table view and edit individually

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

万劫不复 2024-11-16 08:40:34

查看 ABPerson 类参考。还有一系列其他复制函数,包括您要查找的函数,ABAddressBookCopyArrayOfAllPeople(ABAddressBookRef ab)

Look at ABPerson Class Reference. There is a list of other copy functions, including the one you seek, ABAddressBookCopyArrayOfAllPeople(ABAddressBookRef ab)

稚然 2024-11-16 08:40:34

注释掉你的函数并添加这个函数,看看它是否有效

-(BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {


            [peoplePicker dismissModalViewControllerAnimated:NO];

            ABPersonViewController *picker = [[ABPersonViewController alloc] init];
            picker.personViewDelegate = self;
            picker.displayedPerson = person;

// Allow users to edit the person’s information
            picker.allowsEditing = YES;
            [picker setValue:[NSNumber numberWithBool:YES] forKey:@"allowsDeletion"];



            [self.navigationController pushViewController:picker animated:YES];

    return YES;
}

comment out your function and add this one and see if it works

-(BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {


            [peoplePicker dismissModalViewControllerAnimated:NO];

            ABPersonViewController *picker = [[ABPersonViewController alloc] init];
            picker.personViewDelegate = self;
            picker.displayedPerson = person;

// Allow users to edit the person’s information
            picker.allowsEditing = YES;
            [picker setValue:[NSNumber numberWithBool:YES] forKey:@"allowsDeletion"];



            [self.navigationController pushViewController:picker animated:YES];

    return YES;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文