我正在使用ABPeoplePickerNavigationController,它是UINavigationController的一個子類,在上下文中,我使用右側的默認導航欄按鈕「Cancel」,沒有任何意義。我無法找到禁用或隱藏的方法,所使用的任何方法都需要公開和可存儲。 完全擺脫導航欄(picker.navigationBarHidden = YES;)可能是一個選項,除了在彈出回到導航欄重新出現的聯繫人列表之後。 繼承ABPeoplePickerNavigationController和攔截viewWillAppear嘗試和無取消按鈕不起作用。 [picker setAllowsCancel:NO];工作但沒有記錄,所以我預計永遠不會通過審批。ABPeoplePickerNavigationController - 刪除「取消」按鈕而不使用私有方法/屬性?
回答
沒有答案 - 如果你不能接受取消,寫一個新的人員選擇器。
你不能只寫一個「人員選擇器」 - 你需要詢問地址簿許可,這會降低轉換率; Apple的默認人員選擇器不需要系統權限。 – Zorayr 2015-09-01 03:05:44
您可以通過選取器子視圖實現該結果瀏覽。只是有點無聊...
將委託設置爲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];
}
我還沒有嘗試過,但我覺得Uby是說通過選擇器的子視圖迭代,直到你找到一個isKindOfClass:[的UIBarButtonItem類],然後你可以改變它的title屬性。它也可能在navigationBar的'Item'數組中。
一定要爲拾取對象委託(不是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];
}
它工作正常,但在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;
}
它工作得很好。
這個
- (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];
}
完美的作品!
這裏使用委託方法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是導航控制器的頂視圖控制器。
編輯:見下面的評論。這現在是不能做的一個例證。
我試圖通過繼承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];
}
}
順便說一句,你是正確的viewWillAppear:(布爾)沒有工作。視圖已經生效後,我必須觸發killCancelButton。在我的iPhone 4上看起來不會有什麼問題,但我想可以在較老/較慢的設備上看起來很有趣。 – 2012-12-11 00:11:04
看起來很刺眼,因爲當ABPeoplePickerNavigationController顯示爲模態時,它會使用「取消」按鈕進行動畫處理。只有當它停止時,該按鈕被移除。哎呀。 – n13 2013-05-22 10:23:21
我最終建立了自己的視圖/控制器從地址簿框架中獲取模型數據,因爲如上所述,最終確實會出現問題。希望我沒有把任何人誤解爲一種強硬的安全感。 – 2013-07-10 17:51:45
根據羅素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)];
}
- 1. 使用按鈕刪除JSON屬性
- 2. 的ABPeoplePickerNavigationController隱藏取消按鈕
- 3. 刪除取消按鈕從通訊錄
- 4. 刪除屬性的確定和取消按鈕
- 5. 屬性使用在C私有方法++
- 6. 刪除ABPeoplePickerNavigationController中的取消按鈕。奇怪的行爲iOs 4.x
- 7. 無法使用jQuery刪除按鈕的禁用屬性
- 8. 刪除對象的私有屬性
- 9. SonarQube假陽性在靜態方法「未使用私有方法應被刪除」
- 10. 類方法不能使用相同類的私有屬性?
- 11. FirebaseUI iOS刪除取消按鈕
- 12. 刪除UIImagePickerController中的取消按鈕?
- 13. 使用私有靜態方法,而不是私有方法在C#
- 14. 使用地圖更新節點屬性而不刪除現有屬性
- 15. 更改ABPeoplePickerNavigationController屬性
- 16. Swipe刪除單元格而不必按下刪除按鈕Swift
- 17. 靜態方法改變私有屬性
- 18. 刪除JMS消息屬性
- 19. 使用jquerymobile 1.4刪除並添加屬性到按鈕1.4
- 20. 使用JOptionPane刪除窗口的取消按鈕
- 21. IOS 8 - 的ABPeoplePickerNavigationController - 取消委託方法的工作,別人不
- 22. 刪除按鈕而不是鏈接
- 23. 如何取消點擊刪除按鈕時刪除記錄?
- 24. ASP.NET MVC取消而不是刪除
- 25. 無法使用$ _GET方法創建刪除按鈕
- 26. 更改和刪除按鈕的方法
- 27. 使用幫助器私有方法初始化最終屬性
- 28. 有沒有其他方法可以使用Express和Mongoose更新文檔而不必刪除_id屬性?
- 29. 使用按鈕刪除georsslayer
- 30. 使用接口和私有方法取消可測試代碼
試試這個https://gist.github.com/2970980 – 2012-06-22 07:25:08
這可能有助於http://www.scott-sherwood.com/ios5-removing-the-cancel-button-on-abpeoplepickernavigationcontroller/ – c0d3Junk13 2012-09-18 17:58:49
我被困在同樣的問題,只是想說這是絕對的嘲笑蘋果。是的,如果您使用setAllowsCancel或setAllowsCardEditing,則您的應用程序將被拒絕。 – c0d3Junk13 2013-04-19 15:37:00