Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I Got Array Like Following
@"6 objects"
[0]=(_NSDictionary*) 4 key/Value pairs
[0]=@"Home":@"(555)564-8583"
[1]=@"Mobile":@"(415)555-3695"
[2]=@"First Name":@"Kate"
[3]=@"Last Name":@"Bell"
[1]=(_NSDictionary*) 5 key/Value pairs
[2]=(_NSDictionary*) 5 key/Value pairs
[3]=(_NSDictionary*) 5 key/Value pairs
[4]=(_NSDictionary*) 5 key/Value pairs

Now I Want To Display My TableView Like following

Kate Bell
(555)564-8583
(415)555-3695
John Appleseed
Hank Zakroff
David Taylor
Daniel Higgins

In Above TableView Kate Bell Is Expanded And Other All Are Collapsed.It Mean When We Tap On Contact Name At That Time Numbers Will Display And Another Tap It Will Hide.

I am Putting Code By Which I get Mutable Array named (allcontact) Like Above.

Pascal
- (void)getAllContacts {
        
        //[self getPermissionForContacts ];
    NSString *homeno,*mobileno,*workno;
    
        CFErrorRef *error = NULL;
        ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error);
        
        
        
        CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
        CFIndex numberOfPeople = ABAddressBookGetPersonCount(addressBook);
        
        for(int i = 0; i < numberOfPeople; i++) {
            
            ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );
            
            NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty));
            NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty));
            NSLog(@"Name:%@ %@", firstName, lastName);
            
            ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
            
            for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
                NSString *phoneNumber = (__bridge_transfer NSString *) ABMultiValueCopyValueAtIndex(phoneNumbers, i);
                NSLog(@"phone:%@", phoneNumber);
                if (i==0) {
                    homeno=phoneNumber;
                } else if (i==1) {
                    mobileno=phoneNumber;
                }else if (i==2) {
                    workno=phoneNumber;
                }
            }
            
            
             allContactDict = [[NSDictionary alloc] initWithObjectsAndKeys:
                                         firstName,@"First Name",
                                            lastName,@"Last Name",
                                            homeno,@"Home",
                                            mobileno,@"Mobile",
                                            workno,@"Work",nil];
            
            
            [allContact addObject:allContactDict];
            
            
            homeno=@"";
            mobileno=@"";
            workno=@"";
            NSLog(@"=============================================");
          
        }
    
    }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900