0
votes

i am trying to open ABPersonViewController at table delegate method (DidSelectRowAtIndex). but when i tap on one of my contact person in table view it shows "obj msg send". help me here is my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // Fetch the address book 
    if ((people != nil) && [people count])
    {   

        ABAddressBookRef addressBook = ABAddressBookCreate();
        //ABPersonViewController *personController = [[ABPersonViewController alloc] initWithNibName:@"ABPersonViewController" bundle:nil];

        ABRecordRef person = (ABRecordRef)[people objectAtIndex:indexPath.row];     
        ABPersonViewController *personController = [[ABPersonViewController alloc] init];

        personController.addressBook = addressBook;
        personController.personViewDelegate = self;
        personController.displayedPerson = person;
        personController.allowsEditing = YES;       
        //navigationController = [[UINavigationController alloc] init] ;
        [self presentModalViewController:personController animated:YES];
        //[self.navigationController pushViewController:personController animated:YES];
        [personController release];     
    }   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];

}
3
What do you want to achieve? Do you want to get contact person's information?Mehul Mistri
@marvin:i need to open ABPersonViewController when i select any name in contactsin editable mode.user720235

3 Answers

0
votes

Use this line instead of that in your code,

ABPersonViewController *personController = [[ABPersonViewController alloc] initWithNibName:@"ABPersonViewController" bundle:nil];
1
votes

You are doing an unnecessary release here, CFRelease(person);. You are just getting the value directly from an array so you shouldn't release it. Moreover, the ABPersonViewController object doesn't retain the person object assigned to displayedPerson so this results in an error when it tries to access the object which has been released.

1
votes

If you want the personview to open in edit mode, in addition to allowsEditing = YES, you need to specify setEditing:YES:

[personController setEditing:YES animated:NO];