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の色が黒くなるのだがこれはそういうものなのだろうか。
関連記事
-
-
Apple Watch用バッテリーロガーを公開しました
1年前に開発し、App StoreにSubmitしたものの Rejectされ続けていたアプリをその
-
-
[iPhone 開発本] 実践iPad/iPhoneゲームプログラミング 沼田 哲史
MacOS XとiPhone用のゲーム用フレームワーク Karakuri Framework を開発
-
-
Apple Special Event 2011
2011年は iPhone 4s が発表された。 https://japanese.enga
-
-
Apple Special Event 2019
https://japanese.engadget.com/2019/09/10/5-iphone
-
-
[iOS SDK] UIDeviceOrientation ではまる
すぐURLが変更されそうだが、2013/02/16 時点だと、Supporting Multiple
-
-
MangaONEでARMS読み放題期間延長
MangaONE で2015/12/29まで皆川亮二氏の名作ARMSが読み放題、ということで暇をみ
-
-
List切替が便利なTweetList を買ってみた。
フォローする人が増えてくると、なかなかメインのTLを追うのは難しくなる。 このため、複数のListを
-
-
3/8(木)深夜はiPad3の発表?
3/7(水)(日本時間3/8(木)深夜) にAppleのプレスイベントがあり、iPad3 が発表
-
-
iPad用ペン AluPen を買ってみた。
年末に注文したAluPenをようやく入手。品薄で1ヶ月かかってしまった。Amazonで2404円。紹
-
-
KORG USB MIDIコントローラーnanoPAD2購入
2016年あけましておめでとうございます。以前から気になっていたKORG nanoPAD2 がタイム
Comment
NavigationControllerのviewDidLoadあたりで、下のように設定すると必要な大きさだけ表示可能です。
self.contentSizeForViewInPopover = CGSizeMake(width, height);
わざわざ書き込みありがとうございます。
後ほど試してみます。