2

我正在制作一个应用程序,我想在其中访问联系人的名字并将它们存储到 nsmutable 数组中,以便我可以获取该数组的值array[0]array[i-1]在表格视图中打印它们。这是我的代码:

CFErrorRef error = NULL;

ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);

if (addressBook != nil)
{
    contacts_Image_List=[[NSMutableArray alloc]init];
    NSLog(@"Succesful.");

    NSArray *allContacts = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);




    NSUInteger i = 0;
    for (i = 0; i < [allContacts count]; i++)
    {
Person *person = [[Person alloc] init];



        ABRecordRef contactPerson = (__bridge ABRecordRef)allContacts[i];

        NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson, kABPersonFirstNameProperty);
        NSString *lastName =  (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson, kABPersonLastNameProperty);
        NSString *fullName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];

        person.firstName = firstName;
        person.lastName = lastName;
        person.fullName = fullName;

       // person.userThumb[i]=firstName;

       //[person.userThumb[i] addObject:@"firstName"];

       //above line gives null

        NSLog(@"%@",person.userThumb[i]);

我的可变数组在Person.h课堂上。

4

1 回答 1

1

在每次迭代中只做:

[person.yourMutableArray addObject:fullName]

只要确保您的 MutableArray 已经被分配,并且您只分配一次。

于 2013-01-26T02:18:59.843 回答