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の色が黒くなるのだがこれはそういうものなのだろうか。
関連記事
-
-
[iOS] iPhone とつながるG-SHOCKの注意すべき仕様
CASIO 腕時計 G-SHOCK ジー・ショック Bluetooth Low Energy対応
-
-
Mac Fan 2020年 6月号
長女のiPhone 6 の画面がバキバキに割れているので、iPhone SE を購入した。
-
-
Anker の高耐久ライトニングケーブルを買ってみた
立て続けに2本ライトニングケーブルが壊れたので、ふんぱつして高級ケーブルを買ってみた。 たしかに
-
-
iTunes Connect の支払先をCitibankに変更
iTunes Connectからの送金を三井住友銀行の口座で受け取っていたが、毎月4000円の手数料
-
-
Withings WS-50 不具合発生
昨年12月に購入した Withings WS-50をまずまず便利に使っていたのだが、数週間前から、電
-
-
Apple に Bug Report を送信、iOS 11.3で修正された
EverLearnのユーザの方から、toothache の発音がおかしいので直してほしいという依頼が
-
-
[iOS SDK] 物書堂の辞書アプリと連携してみた
物書堂は使い勝手のよい辞書アプリをたくさんリリースしている会社だ。 今作っている英単語学習アプリで
-
-
MacPeople 2012 5月号にはほしいガジェットがたくさん紹介されてる
定期購読しているMacPeopleの今月号(5月号)で面白い製品がたくさん紹介されていたのでメモを書
-
-
App Storeでのアプリ最低価格が突然115円から85円に 2011/07/14
App Storeでのアプリ最低価格が突然日本時間2011/07/14(木)未明に115円から85円
-
-
Xcodeの Console出力をクリアするキーバインド
いつも忘れるので、メモとして残しておく。Command(⌘)+ Kその他はこちら。 Menu Com
Comment
NavigationControllerのviewDidLoadあたりで、下のように設定すると必要な大きさだけ表示可能です。
self.contentSizeForViewInPopover = CGSizeMake(width, height);
わざわざ書き込みありがとうございます。
後ほど試してみます。