我正在尝试在表委托方法(DidSelectRowAtIndex)中打开ABPersonViewController。但是当我在表视图中点击我的一个联系人时,它会显示“obj msg send”。帮我 这是我的代码:
- (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]; }
答案 0 :(得分:1)
你在这里做了一个不必要的发布,CFRelease(person);
。您只是直接从数组中获取值,因此您不应该释放它。此外,ABPersonViewController
对象不会保留分配给person
的{{1}}对象,因此在尝试访问已释放的对象时会导致错误。
答案 1 :(得分:1)
如果您希望人物视图在编辑模式下打开,除了allowsEditing = YES
之外,您还需要指定setEditing:YES
:
[personController setEditing:YES animated:NO];
答案 2 :(得分:0)
使用此行而不是代码中的行
ABPersonViewController *personController = [[ABPersonViewController alloc] initWithNibName:@"ABPersonViewController" bundle:nil];