Reputation: 85
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
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
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
Reputation: 6016
Use this line instead of that in your code,
ABPersonViewController *personController = [[ABPersonViewController alloc] initWithNibName:@"ABPersonViewController" bundle:nil];
Upvotes: 0