2010-06-29 110 views
1

ABPersonViewController默認在右側按鈕欄位置顯示「取消」按鈕。如何隱藏/清除該項目?必填代碼示例如下:ABPersonViewController並隱藏取消按鈕

ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease]; 
picker.personViewDelegate = self; 
picker.displayedPerson = aPerson; 
picker.allowsEditing = NO; 

謝謝。

+0

解決了!子類ABPersonViewController,覆蓋 - (void)viewDidLoad,調用super,然後將rightBarButtonItem設置爲nil。達達! @interface PersonViewController:ABPersonViewController @end @implementation PersonViewController - (無效)viewDidLoad中{ \t [超級viewDidLoad中]; \t self.navigationItem.rightBarButtonItem = nil; } @end – gnasher 2010-06-29 16:33:37

回答

4

已解決!子類ABPersonViewController,覆蓋​​,致電超級,然後將rightBarButtonItem設置爲nil。達達!

@interface PersonViewController : ABPersonViewController 
@end 

@implementation PersonViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.navigationItem.rightBarButtonItem = nil; 
} 

@end 
+0

一定要將自己的答案標記爲已接受,以便其他人可以輕鬆地引用您的解決方案:) – BoltClock 2010-06-29 16:42:17

1

簡單多了:

ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease]; 
picker.personViewDelegate = self; 
picker.displayedPerson = aPerson; 
picker.allowsEditing = NO; 
[self.navigationController pushViewController:picker animated:YES]; 
picker.navigationItem.rightBarButtonItem = nil; // remove "Cancel" button 
[picker release]; 

(簡單地添加rightBarButtonItem =零pushViewController後)。

+0

似乎是iOS 4中的一種迴歸。我的代碼在iOS4之前工作,我可以在其中添加右邊的BarButtonItem現在我必須在包含我的ABPersonViewController的UINavigationController上調用presentModalViewController之後添加它。 – Shazron 2010-08-25 19:56:33