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の色が黒くなるのだがこれはそういうものなのだろうか。

関連記事

no image

iPhone/iPad で教育

この本は面白そう。今後は教育分野での応用も増えていくだろう。 その時に、iPhone/iPad は教

記事を読む

新アプリ「ドラムちゃん」を公開しました

2015年から作りはじめた iPad専用 ドラム譜学習アプリ ドラムちゃん を本日 2017/01/

記事を読む

おんぷちゃん for iPad にオンライン授業サポート機能を追加

コロナウィルスの影響で、うちの子どもたちのピアノレッスンもオンライン授業になりまし

記事を読む

[iOS SDK] UIAlertView が消えた後にキーボードが表示される

昔書いたコードで、UIAlertView に setAlertViewStyle で UIAlert

記事を読む

no image

[iPad開発本] Beginning iPad Development

まだ数が少ないiPad開発本がApressから出たみたい。(Beginning of iPad De

記事を読む

Reject履歴 EverLearn 1.7.0

どうやら Apple Watch対応アプリの審査は厳しいらしいので、Rejectされた履歴を書いてみ

記事を読む

no image

[iPhone SDK] Significant-change Location Service の挙動

iPhoneで位置情報取得を連続して行うと、あっという間に電池が無くなってしまう。これは、位置情報取

記事を読む

[iOS10] NSPhotoLibraryUsageDescription

iOS10 になってから App Store にアプリのSubmitを行ったところ、アプリのアップロ

記事を読む

Xcode 9.2 Install

久しぶりに週末に休みが取れたので、ブログを書いてみる。iPhone 7 Plus に1分ごとに再起動

記事を読む

[iOS SDK] Miselu C.24 対応(Bluetooth MIDI対応)

自作アプリの Miselu C.24 対応(というかBluetooth MIDI対応)を行ったので、

記事を読む

Comment

  1. tilde より:

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

    self.contentSizeForViewInPopover = CGSizeMake(width, height);

  2. admin より:

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

Message

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Ember Mug 2のACアダプタをUSB Type-Cに変えてみた

冬になると活躍する Ember Mug 2 の充電器は付属のACアダ

Wi-Fi6Eルータ TP-Link AXE5400購入

Wi-Fi6E を試してみたくなり、TP-Link AXE5

児童手当 認定請求書申請 2024 「請求者が養育をする18歳に達する日以降の最初の3月31日までの子の数」とは?

2024年に受給していない人には手紙が届くらしい。 電子申請も

Vision Proアプリ開発本 8/24、8/26に発売

Vision Proアプリ開発入門 P400が 8/24 に発売、V

Developer Strap が日本でも購入可能に

USアカウントでしか購入できなかった Vision Pro 用 De

→もっと見る

PAGE TOP ↑