ABPeoplePickerNavigationControllerの「Group」ボタンを削除する方法を調べてみた。
邪魔だったので調べてみた。
手順
1. ABPeoplePickerNavigationControllerのデリデートを設定するクラスに「ABPeoplePickerNavigationControllerDelegate」に加え、「UINavigationControllerDelegate」を追加する。
@interface SampleViewController : UIViewController <ABPeoplePickerNavigationControllerDelegate, UINavigationControllerDelegate> { @private ... } @end
2. ABPeoplePickerNavigationControllerを作成する際に、「delete」プロパティを設定する。
@implementation - (void) _launchPeoplePickerView { ABPeoplePickerNavigationController * nextView = [[[ABPeoplePickerNavigationController alloc] init] autorelease]; nextView.peoplePickerDelegate = self; nextView.delegate = self; // ←これを加える [self presentModalViewController:nextView animated:YES]; } @end
3. UINavigationControllerDelegateのデリゲートメソッド「navigationController:willShowViewController:animated」をオーバライドし、以下のロジックを実装する。
- (void) navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { // 左側の「Groups」ボタンを削除する。 // navigationControllerは、上記のnextViewそのもの。 // setLeftButtonItemにnilを設定することで、ボタンが消えます。 [navigationController.topViewController.navigationItem setLeftBarButtonItem:nil]; }
実行結果
実行結果は以下の通り。同じようなことをすれば、キャンセルボタンも消せると思います。
実行環境
- OSX 10.8.2
- Xcode 4.5.2
- iOS 6.0 @シミュレーター