iPhone開発のネタ帳: UIPopoverController に UIPickerView をいれる
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の色が黒くなるのだがこれはそういうものなのだろうか。
関連記事
-
-
App Store の Kids Category にアプリを公開する その2
Kids Category でアプリを公開してもらうために Submit したところ、見事に Rej
-
-
[iPhone開発本] オライリー iPhoneアプリケーション開発ガイド 感想その1
面白そうだったので発売日に買ってみた。1995円と安いのもすばらしい。 しかしタイトルは一ひねりした
-
-
iPhoneアプリの無料版と有料版を同じソースから作りたい
こども向けに作った自作アプリおんぷちゃんは、習作でもあったのでiPhone無料版、iPhone有料版
-
-
MacPeople 2012 5月号にはほしいガジェットがたくさん紹介されてる
定期購読しているMacPeopleの今月号(5月号)で面白い製品がたくさん紹介されていたのでメモを書
-
-
Pro iPhone Game Development は発売延期らしい
面白そうだったので結構前にAmazonで注文したのだが、ずっと発売されず、おかしいとおもって発売元の
-
-
LogLocations 1.4.0 写真表示対応
行動ログは取りたいが、何も操作したくない。という自分のようなずぼらなログ好きユーザ向けのアプリ、L
-
-
最近読んだ本 iPhoneデジカメプログラミング
カメラアプリを作る予定はなかったので2011年3月に発売されてからしばらく様子を見ていたが、そろそろ
-
-
Corona SDK 新バージョンリリース
Corona SDKの新バージョンが出た。 Corona SDK: New additions an
-
-
Apple Watch 対応アプリようやくSubmit完了
ようやく Apple Watch 対応したアプリのSubmitが完了した。 とりあえずの対
-
-
iPhone/Androidアプリで週末起業(山崎潤一郎著) を読んでみた。
前著を読んで、ちょっと楽観的に書きすぎていると思ったけれどもとりあえず最新版が出たので読んでみた。
Comment
NavigationControllerのviewDidLoadあたりで、下のように設定すると必要な大きさだけ表示可能です。
self.contentSizeForViewInPopover = CGSizeMake(width, height);
わざわざ書き込みありがとうございます。
後ほど試してみます。