2

UITabBarController で iPhone の連絡先帳から連絡先を表示しようとしています。私はこれまでに来ました:

- (void)contacts 
{
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
// place the delegate of the picker to the controller
picker.peoplePickerDelegate = self;

CGRect newFrame = self.tabBarController.view.frame;
newFrame.size.height = newFrame.size.height - 49;
picker.view.frame = newFrame;
[picker setAccessibilityViewIsModal:YES];
// showing the picker
[self.tabBarController presentModalViewController:picker animated:NO];
}

呼び出し:

-(void)viewWillAppear:(BOOL)animated
{
   [self contacts];
}

結果として、私はこれを得ています:

ここに画像の説明を入力

  1. タブが見えない
  2. タブのスタイルは黒ですが、ピッカーは青です。
  3. キャンセルボタンがあります。

タブを表示する方法、スタイルを黒くする方法、キャンセル ボタンを取り除く方法は?

前もって感謝します。

編集:

メソッドを変更した後:

-(void)contacts
{
   ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.navigationBar.tintColor=[UIColor blackColor];
// Display only a person's phone, email, and birthdate
NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty], nil];
picker.displayedProperties = displayedItems;
// Show the picker
picker.navigationBar.hidden=YES;
CGRect newFrame = picker.view.frame;
newFrame.size.height = newFrame.size.height - 49;
picker.view.frame = newFrame;

[self.tabBarController.view addSubview:picker.view];

}

私はこの結果を得ました:

ここに画像の説明を入力

はい、連絡先はタブ内に座っていますが、現在問題があります:

  1. 連絡先でtableViewに触れると、連絡先がまったく消えてしまいます。
  2. タブを切り替えても、連絡先ビューが消えず、すべてのタブで表示されます。
  3. UISearchbar の半分は非表示のままです。

悪は今どこに?

4

2 に答える 2

2

You are presenting the view controller on top of the tabBarController, that is why the tabBar is hidden. Try something like:

UIViewController *controller = [tabBarController.viewControllers objectAtIndex:0]; // Let's assume this is the desired view controller that should display the ABPeoplePickerNavigationController
[controller presentModalViewController:picker animated:NO];

Keep in mind, presenting a UIViewController (subclass) underneath a tabbar controller might result in some really strange user experience. Furthermore, you will have to set a table view bottom inset (same height as the tabBar, which is normally 49px) to the ABPeoplePickerNavigationController in order to view the very last entry of the table.

ABPeoplePickerNavigationController has a navigationBar property, you can change it's tint color to (e.g.) black:

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.navigationBar.tintColor = [UIColor blackColor];

I doubt you will be able to remove the cancel button without being rejected at the app approval process. Furthermore, there is no property of the cancel button within the ABPeoplePickerNavigationController, so you will have to get the reference from e.g. scan through the navigationBar subviews.

于 2012-04-26T23:17:11.787 に答える
1

もうお分かりだと思いますが、それはモーダル ビュー コントローラーがアクティブ ウィンドウの上部に追加されているためです。そのため、タブ バーの上に移動します。 おそらくあなたにとってよりうまくいくUIViewController方法もあります。presentViewController:animated:completion:プロパティを使用してアニメーションのタイプを指定する場合、いくつかのアニメーション オプションがありmodalTransitionStyleます。頑張ってください(まだ質問がある場合でも)。

于 2012-11-13T21:34:17.370 に答える