user720235
user720235

Reputation: 85

donot open ABPersonViewController

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];

}

Upvotes: 0

Views: 686

Answers (3)

zosmac
zosmac

Reputation: 11

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];       

Upvotes: 1

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

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.

Upvotes: 1

Use this line instead of that in your code,

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

Upvotes: 0

Related Questions