Indexlist in uitableView not working

89 views Asked by At

I am making a contacts app in which i am fetching the abaddressbook in the uitableview . I am doing this by taking Person (NSObject class). Now i need to implement a indexlist which takes me to the section header like in contacts and music player app . I need indexlist like this

https://i.stack.imgur.com/owyXV.png

My addressbook is working fine, But i dont know how can make indexlist work in this

My code for fetching addressbook is :-

      - (void)listPeopleInAddressBook:(ABAddressBookRef)addressBook
 {

ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
allPeople = (__bridge NSMutableArray *)(ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonFirstNameProperty));
NSInteger numberOfPeople = [allPeople count];
for (NSUInteger i = 0; i < numberOfPeople; i++) {
    Person *personContact = [[Person alloc]init];

    person = (__bridge ABRecordRef)allPeople[i];

    NSString *firstName = (__bridge NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    NSString *lastName  = CFBridgingRelease(ABRecordCopyValue(person, kABPersonLastNameProperty));
    if (firstName == nil ) {
        firstName = @"";
    }
    if (lastName == nil)
    {
        lastName = @"";
    }

    NSString *fullName = [NSString stringWithFormat:@"%@ %@",firstName,lastName];

    personContact.firstName = firstName;
    personContact.lastName = lastName;
    personContact.fullName = fullName;

    // ***************************** for adding multiple contacts ********************************



ABMultiValueRef phoneNumbers = ABRecordCopyValue((person), kABPersonPhoneProperty);

    CFIndex numberOfPhoneNumbers = ABMultiValueGetCount(phoneNumbers);
    for (CFIndex i = 0; i < numberOfPhoneNumbers; i++) {
        NSString *phoneNumber = CFBridgingRelease(ABMultiValueCopyValueAtIndex(phoneNumbers, i));

        if ([phoneNumber isEqualToString:@""])
        {
            phoneNumber = @"Not Available";
        }

        NSCharacterSet *trim = [NSCharacterSet characterSetWithCharactersInString:@"#();$&-+"];
        phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet: trim] componentsJoinedByString: @""];
        phoneNumber= [phoneNumber stringByReplacingOccurrencesOfString:@"\"" withString:@""];
        phoneNumber=[phoneNumber stringByReplacingOccurrencesOfString:@"" withString:@""];

        personContact.phoneNumber = phoneNumber;

        [phoneArray addObject:phoneNumber];

//************************************ Emails ********************************************8

        ABMutableMultiValueRef eMail  = ABRecordCopyValue(person, kABPersonEmailProperty);
        if(ABMultiValueGetCount(eMail) > 0)
        {
            email =CFBridgingRelease(ABMultiValueCopyValueAtIndex(eMail, 0));
        }
        else
        {
            email =  @"";
        }
        personContact.email = email;
    }

//*******************************photossssssss*************************************************

    CFDataRef imgData = ABPersonCopyImageData(person);
    NSData *imageData = (__bridge NSData *)(imgData);

    phoneImage = [UIImage imageWithData:imageData];
    if (phoneImage == nil) {
        phoneImage = [UIImage imageNamed:@"userEdit"];
    }
    CGSize destinationSize = CGSizeMake(70, 70);
    UIGraphicsBeginImageContext(destinationSize);
    [phoneImage drawInRect:CGRectMake(0, 0, destinationSize.width, destinationSize.height)];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    if (imgData != NULL)
    {
        CFRelease(imgData);
    }
    personContact.photos = (NSString *)newImage;

    [contactsData addObject:personContact];
    [contactstableView reloadData];

}
}

Please help me in implementing and using index list like music player app.

0

There are 0 answers