iPhone開発のネタ帳: UIPopoverController に UIPickerView をいれる

公開日: : 最終更新日:2012/06/30 iPad

iPad から追加された部品の一つに、UIPopoverController がある。
iPadが出るまではNDAのためブログにも書けなかったが、今はApple公式ページにReferenceが公開されている。

自作アプリでは、iPhone版では設定画面のためにNavigationControllerを使って全画面で設定を行っているが、iPadからは基本的に全画面の遷移はなくなり、必要に応じてPopupを使うことになっている。(iPad HIG: Human Interface Guideline 参照)

このため、iPhone版で用意している設定画面を UIPopoverControllerで用意することとした。
UIPopoverController は中にどんなUIViewControllerでもいれることができるらしい。
– (id)initWithContentViewController:(UIViewController *)viewController
でPopoverを作成する。
実際のコードは下記のようなもの。NavigationController には UITableView をいれている。

-(IBAction)settingsButtonPressed:(id)sender {
if (!mPopoverController) {
NSString *settings = NSLocalizedString(@"Settings", @"Settings");

SettingViewController *settingVC = [[SettingViewController alloc]initWithStyle:UITableViewStyleGrouped];
UINavigationController* theNavController = [[UINavigationController alloc] initWithRootViewController:settingVC];
theNavController.navigationBar.topItem.title = settings;
[theNavController setNavigationBarHidden:NO];
[theNavController setToolbarHidden:NO];

mPopoverController = [[UIPopoverController alloc]initWithContentViewController:theNavController];
mPopoverController.delegate = self;
[settingVC release];
[theNavController release];
}
if(!mPopoverController.popoverVisible) { // visible でない場合
[mPopoverController presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}

設定画面の中で、数値を選ぶ必要があったので、SettingViewControllerから、UIPickerViewを呼び出すようにした。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger section = [indexPath section];

switch (section) {
case 0: {
[self.navigationController pushViewController:mMondaisuPickerVC animated:YES];
break;
}
default:
break;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

分からないこと:

UIPopoverController が画面一杯まで表示されてしまう。必要な大きさだけ表示したいのだが。UIPickerView を表示すると特に無駄スペースが多い。
UIPickerView に遷移するとPopoverの色が黒くなるのだがこれはそういうものなのだろうか。

関連記事

[Xcode 9.3] iOS 11.3にしたら Xcode 9.3 + High Sierra が強制された

High Sierra はいろいろとアグレッシブな変更が入っており不安定と聞いていたので避けて通って

記事を読む

no image

iPhoneアプリの無料版と有料版を同じソースから作りたい

こども向けに作った自作アプリおんぷちゃんは、習作でもあったのでiPhone無料版、iPhone有料版

記事を読む

おんぷちゃん 1.9.0 MIDI対応

おんぷちゃん 1.9.0 で MIDI キーボードに対応しました。(まだ App Store にてレ

記事を読む

no image

[iOS SDK] CGRect 関連の便利機能

CGRect を使っていていつも忘れて調べてしまうのでメモしてみる。 CGRect の変数を拡大・

記事を読む

no image

達人出版会の本をKindleで読んでみる(Windows編)

最近話題の「当事者」の時代の電子書籍版(パブー)や、エキスパート Objective-C プログラミ

記事を読む

no image

スティーブ・ジョブズの王国 ― アップルはいかにして世界を変えたか?

Amazonからおすすめされてたまたま発見した本。2010年11月12日発売らしい。 原書はRetu

記事を読む

no image

[英単語学習法] MyShortcuts を使って通知センターからいろいろな辞書を引いてみる

MyShortcuts+Viewer 価格: ¥100

記事を読む

no image

Xcode4 の初Submit作業ではまる 2011/07/11

昨夜、タッチ! にほんちずHDの次のアプリを検証していて、iPadを回転させるとアプリが異常終了して

記事を読む

no image

GTD用にOmniFocusを購入

半年くらいMacBookとiPhoneでOmniFocusを使っている。 なかなか良いので、紹介して

記事を読む

no image

AirMac Extreme Base Station がほしい 2011/05/07

自宅の無線LANルータが不安定なので、AirMac Extremeを買おうかと悩み中。 自宅にApp

記事を読む

Comment

  1. tilde より:

    NavigationControllerのviewDidLoadあたりで、下のように設定すると必要な大きさだけ表示可能です。

    self.contentSizeForViewInPopover = CGSizeMake(width, height);

  2. admin より:

    わざわざ書き込みありがとうございます。
    後ほど試してみます。

Message

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

ポモドーロテクニック用物理タイマーならTime Timer

会社ではなかなか自由に時間を使えないが、家で読書や作業をする

DELL 32インチディスプレイ U3223QE 購入

Dell U3223QE は解像度 3840x216

WWDC 2023 Vision Pro発表

2023/6/5 (日本時間 2023/06/06 2AM)のWWD

M1 MacBook Air を Venturaにアップデートする

M1 MacBook Air を macOS Montere

iOS16でaurioTouch の inBufferFramesが1になる

https://developer.apple.com/librar

→もっと見る

PAGE TOP ↑