2011-06-03 70 views
0

我想在表委託方法(DidSelectRowAtIndex)上打開ABPersonViewController。但是當我在表格視圖中點擊我的一個聯繫人時,它顯示「obj msg send」。幫我 這裏是我的代碼:donot open ABPersonViewController

 
- (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

你想實現什麼?你想獲得聯繫人的信息嗎? – 2011-06-03 07:36:20

+0

@marvin:當我在可編輯模式下選擇聯繫人中的任何名稱時,我需要打開ABPersonViewController。 – user720235 2011-06-03 09:57:07

回答

0

使用該行,而不是在你的代碼,

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

您在這裏做一個不必要地釋放,CFRelease(person);。你只是直接從數組中獲取值,所以你不應該釋放它。而且,ABPersonViewController對象不會保留指定給displayedPersonperson對象,因此當它嘗試訪問已釋放的對象時會導致錯誤。

+0

人包含有關contacts..so的信息我應該怎麼做? – user720235 2011-06-03 09:58:03

+0

我沒有得到你。刪除'CFRelease'不起作用? – 2011-06-03 09:59:22

+0

當我使用presentmodal視圖控制器它顯示ABPersonviewcontroller沒有編輯模式。但是當我使用導航,然後它終止。我猜我的導航不工作.. – user720235 2011-06-03 10:33:36

1

如果你想personview在編輯模式下打開,除了allowsEditing = YES,你需要指定setEditing:YES

[personController setEditing:YES animated:NO];  
相關問題