TabBar の UISplitViewController ( UITabBarController )?
質問
タブベースのアプリケーションを開始する必要があり、1 つ以上のタブの分割ビューが必要な状況にあります。ただし、TabbarControllerにSplit View Controllerオブジェクトを追加することはできないようです。(タブバーオブジェクトをsplitviewcontrollerに追加することはできますが)。
この問題は別の方法でも見ることができます。左側の部分に全画面があり、テーブルビューがあり、テーブル内の行が選択されると、その行を指すポップオーバーが表示されます。ポップオーバーの行が選択されると、このポップオーバーの行が選択した行の下の左側に表示され (この行のみが表示されます)、選択した行から別のポップオーバーが表示されます。(パンくずナビゲーションタイプ)
私が説明した内容は明確だと思います。それで、何かアイデアや回避策はありますか?
私の質問が明確でない場合はお知らせください。
ありがとう、
マドハップ
解決 3
私は、サンプルアプリケーションを作りました。そして、私たちは次のようにプログラム的にそれを行うことができます見つけます:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSMutableArray *array = [NSMutableArray array];
NSMutableArray *tabArray = [NSMutableArray array];
UISplitViewController *splitViewConntroller = [[UISplitViewController alloc] init];
MainViewController *viewCont = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
[array addObject:viewCont];
[viewCont release];
viewCont = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
[array addObject:viewCont];
[viewCont release];
[splitViewConntroller setViewControllers:array];
[tabArray addObject:splitViewConntroller];
[splitViewConntroller release];
array = [NSMutableArray array];
splitViewConntroller = [[UISplitViewController alloc] init];
viewCont = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
[array addObject:viewCont];
[viewCont release];
viewCont = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
[array addObject:viewCont];
[viewCont release];
[splitViewConntroller setViewControllers:array];
[tabArray addObject:splitViewConntroller];
[splitViewConntroller release];
// Add the tab bar controller's current view as a subview of the window
[tabBarController setViewControllers:tabArray];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
return YES;
}
この情報がお役に立てば幸いです。
他のヒント
インタフェースビルダを使用して、分割ビューコントローラとタブバーコントローラを作成し、あなたの店にリンクします:
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
アプリのデリゲートdidFinishLaunchingWithOption
では、タブバーコントローラにあなたの分割ビューコントローラを割り当てます:
splitViewController.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"Title" image:nil tag:0] autorelease];
NSArray *controllers = [NSArray arrayWithObjects:splitViewController, /* other controllers go here */ nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
これは、すべての方向に正しく表示され、(この場合は1つだけのタブで)タブバーコントローラを作成します。
私は、デバイスの向きに応じ配向自体を変更するために耳を傾けますUISplitViewControllerのためのサブクラスを書いています。このクラスでは、私は今、UITabBarController内の分割ビューを配置することができ、それぞれの分割ビューは、それが最前面タブではありません場合でも、回転時に正しく動作します。私は正常に TexLege の中でこれを展開してきましたし、それは、App Storeでの使用が承認されましたが、あなたのマイレージは異なる場合があります。 Githubのリポジトリを参照してください。
フォークしてそれを変更すること自由に感じ、と私はいつもそれについてのコメント(または苦情を)聞くに興味があります。 https://github.com/grgcombs/IntelligentSplitViewController の
tabbarcontrollerは(クラスUITabBarControllerのカテゴリを使用して、そう言って)それがサポートされますか向きがなるように、あなたがtabbarcontrollerを書き換える必要がありますsplitviewcontrollerのマスタービューとして表示されるようにするには、
既存のタブバーインターフェイスに分割ビューコントローラの改造についての私の記事を参照してください:<のhref =「http://markivsblog.blogspot.com/2010/04/retrofitting-ipad-uisplitviewcontroller.html」のrel = "nofollowをnoreferrer 「> http://markivsblog.blogspot.com/2010/04/retrofitting-ipad-uisplitviewcontroller.html の
回転メッセージをそれに含まれるすべての UISplitViewController に適切に伝播する UITabBarController サブクラスを作成しました。これにより、UISplitViewController の正しい内部状態が維持されます。ただし、SplitViewController が表示されない場合、SplitViewController デリゲート メソッドの 1 つが呼び出されないため、詳細ビュー コントローラーの viewWillAppear メソッドでこれを考慮します。iOS5.0~iOS6.1で動作を確認しています。
OSTabBarController.m
#import "OSTabBarController.h"
@implementation OSTabBarController
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
for(UIViewController *targetController in self.viewControllers){
if(targetController != self.selectedViewController && [targetController isKindOfClass:[UISplitViewController class]]){
[targetController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
}
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
for(UIViewController *targetController in self.viewControllers){
if(targetController != self.selectedViewController && [targetController isKindOfClass:[UISplitViewController class]]){
[targetController didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
}
}
@end
詳細ビューコントローラー
@implementation OSDetailViewController
-(void)viewWillAppear:(BOOL)animated{
//the splitViewController:willHideViewController:withBarButtonItem:forPopoverController: may not have been called
if(!UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){
self.navigationItem.leftBarButtonItem = nil;
}
}
#pragma mark - UISplitViewControllerDelegate Methods
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
}
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
}
@end
OS 3.2のタブバーのビューとしてsplitviewのための適切なサポートを提供していないことに注意してください。
あなたはそれを「仕事」を作ることができますが、それはバグを持っています - 最大は、別のタブの表示になる配向の変化は、多くの場合、あなたはそれに戻ったときにビューが奇抜行く作り、適切splitviewタブビューに伝播しないということです(等、左側面図は、画面を引き継ぎ、又はbarbutton項目が欠落しています)。
私はこの問題が原因のtabBarControllerで使用するために自分のsplitviewを作成する必要が結論に達しました。
私はAppleが修正に取り組んでいたという噂を聞いていたが、それは今ヶ月をされていると何のiPadのOSの更新が発生していない - 多分iPad用OS 4は、それに対処します。
。あなたはtabtabを構築し、splitviewcontrollerにタブを変更するためにIBを使用することができます。
-(void) makeSplitViewController {
NSMutableArray *controllers = [NSMutableArray arrayWithArray:tabBarController.viewControllers];
int index = 0;
for (UIViewController *controller in tabBarController.viewControllers) {
if ([controller.tabBarItem.title isEqualToString:@"Stock"]) {
stockDetailController = [[StockDetailController alloc] initWithNibName:@"StockDetailController" bundle:nil];
stockMasterController = [[StockMasterController alloc] initWithStyle:UITableViewStylePlain];
stockMasterController.navigationItem.title = date;
stockMasterController.stockDetailController = stockDetailController;
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:stockMasterController] autorelease];
splitViewController = [[UISplitViewController alloc] init];
splitViewController.tabBarItem = controller.tabBarItem;
splitViewController.viewControllers = [NSArray arrayWithObjects:nav, stockDetailController, nil];
splitViewController.delegate = stockDetailController;
[controllers replaceObjectAtIndex:index withObject:splitViewController];
}
index++;
}
tabBarController.viewControllers = controllers;
}
iOS5以降のiPad上でUISplitViewControllerをUITabViewController内に持つことに成功しました。
長い話を短くします:それは動作します:
- ポートレートでも分割を受け入れる場合は、すぐに使用できます。
- マスタービューをポートレートに隠したい場合、ボタンをタップするだけでのみ表示される場合は、少しの作業で。
2 番目のケースのコツは、IntelligentSplitViewController (いくつかの投稿を参照してください。Greg Combs に感謝) を使用するか、同様に UISplitVC を拡張し、SplitView コントローラーのサブクラスのデリゲートが常にライブ オブジェクトであることに注意することです。
以下のプロセスについて詳しく説明しました。