「ひとかじりのりんご」

へっぽこエンジニアの備忘録。こちらは旧ブログ。新しい方はこちら→「http://sbkro.github.io」

ABPeoplePickerNavigationControllerで、「Pushing a navigation controller is not supported」っていう例外が出た。

iOSのコーディング中にエラーが出たのでメモ書き。

とあるViewControllerからABPeoplePickerNavigationControllerを呼び出した際に、このようなエラーが発生してしまった。

2012-10-15 23:20:48.767 hogehoge [26557:c07] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'


どうやら、iOS AddressBookプログラミングガイドのP.20によると、ABPeoplePickerNavigationControllerは、モーダルでの呼び出ししか対応していないらしい。

4. presentModalViewController:animated:メソッドを使用して、PeopleピッカーをモーダルView Controllerとして表示します。表示にはアニメーションを使用することをお勧めします


自分の書いたコードはこちら。

ABPeoplePickerNavigationController * nextView = 
[[[ABPeoplePickerNavigationController alloc] init] autorelease];
nextView.peoplePickerDelegate = self;
[self.navigationController pushViewController:nextView animated:YES];


なので、以下のようにコードを修正。

ABPeoplePickerNavigationController * nextView = 
[[[ABPeoplePickerNavigationController alloc] init] autorelease];
nextView.peoplePickerDelegate = self;
[self presentModalViewController:nextView animated:YES];