2009-10-23 46 views
5

我正在使用ABPeoplePickerNavigationController,它是UINavigationController的一個子類,在上下文中,我使用右側的默認導航欄按鈕「Cancel」,沒有任何意義。我無法找到禁用或隱藏的方法,所使用的任何方法都需要公開和可存儲。 完全擺脫導航欄(picker.navigationBarHidden = YES;)可能是一個選項,除了在彈出回到導航欄重新出現的聯繫人列表之後。 繼承ABPeoplePickerNavigationController和攔截viewWillAppear嘗試和無取消按鈕不起作用。 [picker setAllowsCancel:NO];工作但沒有記錄,所以我預計永遠不會通過審批。ABPeoplePickerNavigationController - 刪除「取消」按鈕而不使用私有方法/屬性?

+0

試試這個https://gist.github.com/2970980 – 2012-06-22 07:25:08

+0

這可能有助於http://www.scott-sherwood.com/ios5-removing-the-cancel-button-on-abpeoplepickernavigationcontroller/ – c0d3Junk13 2012-09-18 17:58:49

+0

我被困在同樣的問題,只是想說這是絕對的嘲笑蘋果。是的,如果您使用setAllowsCancel或setAllowsCardEditing,則您的應用程序將被拒絕。 – c0d3Junk13 2013-04-19 15:37:00

回答

0

沒有答案 - 如果你不能接受取消,寫一個新的人員選擇器。

+0

你不能只寫一個「人員選擇器」 - 你需要詢問地址簿許可,這會降低轉換率; Apple的默認人員選擇器不需要系統權限。 – Zorayr 2015-09-01 03:05:44

0

您可以通過選取器子視圖實現該結果瀏覽。只是有點無聊...

0

將委託設置爲PeoplePickerController控制器。 在委託類中,有這個委託方法。

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
{ 
UIView *pCustomView = [[UIView alloc] initWithFrame:CGRectMake(0,0,0,0)]; 
UIBarButtonItem *pBtn = [[UIBarButtonItem alloc] initWithCustomView:pCustomView]; 
[viewController.navigationItem setRightBarButtonItem:pBtn animated:NO]; 
[pBtn release]; 
[pCustomView release]; 
} 
0

我還沒有嘗試過,但我覺得Uby是說通過選擇器的子視圖迭代,直到你找到一個isKindOfClass:[的UIBarButtonItem類],然後你可以改變它的title屬性。它也可能在navigationBar的'Item'數組中。

0

一定要爲拾取對象委託(不是peoplePickerDelegate,只是委託)設置爲實現以下方法的類:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { 
UIView *custom = [[UIView alloc] initWithFrame:CGRectMake(0,0,0,0)]; 
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:custom]; 
[viewController.navigationItem setRightBarButtonItem:btn animated:NO]; 
[btn release]; 
[custom release]; 
} 
0

它工作正常,但在iOS 4的還有一件事。當使用快速應用切換功能切換回我的應用時,取消按鈕再次出現。

的方法

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

不會被調用。所以我做了這個:

- (void)applicationDidEnterBackground:(UIApplication *)application { 
    id topView = pickerControllerDelegate.peoplePicker.topViewController; 
    topView.navigationItem.rightBarButtonItem = nil; 
} 

它工作得很好。

4

這個

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { 
    UIView *custom = [[UIView alloc] initWithFrame:CGRectMake(0.0f,0.0f,0.0f,0.0f)]; 
    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:custom]; 
    //UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAction)]; 
    [viewController.navigationItem setRightBarButtonItem:btn animated:NO]; 
    [btn release]; 
    [custom release]; 
} 

完美的作品!

2

這裏使用委託方法navigationController:willShowViewController:animated:do work的例子,但它可能是你想要在你自己的控制器中添加自己的導航項的情況,並且給定的選項將刪除你可能設置的任何東西在你自己的控制器中。這裏的代碼,我已經成功地得到這個選項來運行良好:

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

    // Here we want to remove the 'Cancel' button, but only if we're showing 
    // either of the ABPeoplePickerNavigationController's top two controllers 
    if ([navigationController.viewControllers indexOfObject:viewController] <= 1) { 

     viewController.navigationItem.rightBarButtonItem = nil; 
    } 
} 

注意,有兩個視圖控制器導航控制器的堆棧,一個聯絡小組和一個用於聯繫人列表。這就是爲什麼我們不能只檢查fi viewController是導航控制器的頂視圖控制器。

0

編輯:見下面的評論。這現在是不能做的一個例證。

我試圖通過繼承ABPeoplePickerNavigationController並攔截所有更改當前導航視圖控制器視圖的事件來獲取期望的行爲與公共API。然後,可以導航視圖層次結構並清除所有不需要的按鈕。

您可以從委託中瀏覽視圖層次結構,但是您不知道更改視圖狀態的事件......這使得很難終止「取消」按鈕並使其保持不變。

此代碼工作對我來說(注:它蠻力殺死所有的右側按鍵):

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
    [self killCancelButton]; 
} 

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { 
    [super pushViewController:viewController animated:animated]; 
    [self killCancelButton]; 
} 

- (UIViewController*)popViewControllerAnimated:(BOOL)animated { 
    UIViewController *result = [super popViewControllerAnimated:animated]; 
    [self killCancelButton]; 
    return result; 
} 

- (void)killCancelButton { 
    for (NSUInteger itemIdx = 0; itemIdx < self.navigationBar.items.count; itemIdx++) { 
     UINavigationItem *item = [self.navigationBar.items objectAtIndex:itemIdx]; 
     item.rightBarButtonItems = [[NSArray alloc] init]; 
    } 
} 
+0

順便說一句,你是正確的viewWillAppear:(布爾)沒有工作。視圖已經生效後,我必須觸發killCancelButton。在我的iPhone 4上看起來不會有什麼問題,但我想可以在較老/較慢的設備上看起來很有趣。 – 2012-12-11 00:11:04

+0

看起來很刺眼,因爲當ABPeoplePickerNavigationController顯示爲模態時,它會使用「取消」按鈕進行動畫處理。只有當它停止時,該按鈕被移除。哎呀。 – n13 2013-05-22 10:23:21

+0

我最終建立了自己的視圖/控制器從地址簿框架中獲取模型數據,因爲如上所述,最終確實會出現問題。希望我沒有把任何人誤解爲一種強硬的安全感。 – 2013-07-10 17:51:45

0

根據羅素B您可以只覆蓋你viewdidapper

這個工作對我來說:

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
    UINavigationItem *item = (UINavigationItem *)[self.navigationBar.items lastObject]; 
    item.rightBarButtonItems = [[NSArray alloc] init]; 

    item.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addPerson)]; 
} 
相關問題