2014-09-24 65 views
12

我想通過添加自定義UIBarButtonItem作爲UINavigationController的頂視圖控制器的左右barbuttonitem來自定義ABPeoplePickerNavigationController的導航欄。此功能在iOS7和以前的版本工作正常,但不是在iOS的8在iOS 8中自定義ABPeoplePickerNavigationController的導航欄

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 

navigationController.topViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewContact:)]; 

navigationController.topViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)]; 
} 

正在執行上面的代碼,但它沒有任何效果。 PeoplePickerNavigationController顯示其默認導航欄及其默認項目Groups和Cancel按鈕。

iOS 8中發生了什麼變化?我是否需要重新實施,我已經做了什麼?

編輯: 我在導航堆棧中記錄了頂部ViewController。它被稱爲CNContactPicker

+0

您是否嘗試過設置? navigationController.topViewController.navigationItem.rightBarButtonItems navigationController.topViewController.navigationItem.leftBarButtonItems 代替rightBarButtonItem和leftBarButtonItem – 2014-09-26 05:51:44

+0

是的,試過了。但它不起作用。 – 2014-09-26 06:20:07

+0

@XaviValero,我遇到了和你一樣的問題。你有沒有找到解決方案?我會很感激,如果你能幫助我 – 2015-08-31 08:07:40

回答

1

我會帶一個鏡頭:

在IOS 8,我相信蘋果已經爲擴展這個莫名其妙。這意味着代碼是聯繫人應用程序的。它可能在另一個環境中運行。

我認爲這是因爲我讀到您不再需要詢問用戶使用這些拾取器的聯繫人列表訪問權限。這意味着它們不是您自己的應用程序的一部分,即擴展。

可能有一種方法可以防止這種情況發生。我敢打賭,你必須將ABAddressBook傳遞給選取器才能做到這一點。