MGSplitViewController不是RootView,而是在UIViewController中

我对iOS编程非常陌生(来自Java / C ++)。 我试图设置一个TabBarController的应用程序,其中一个选项卡应该是一个SplitView。 我已经完成了我的研究,我知道UISplitview将无法正常工作,并且在任何地方都有人推荐使用MGSplitViewController。 我已经看了演示,但我只是无法弄清楚如何使用它没有它的应用程序的根视图beeing,无法find任何示例代码,可以帮助所以这里是我做什么从演示的类一个单独的UIViewController类,我后来添加到TabBarController:这是我的课:

#import <UIKit/UIKit.h> #import "MGSplitCornersView.h" #import "RootViewController.h" #import "DetailViewController.h" @interface ChannelViewController : UIViewController { MGSplitViewController *splitViewController; RootViewController *rootViewController; DetailViewController *detailViewController; } @property (nonatomic, retain) MGSplitViewController *splitViewController; @property (nonatomic, retain) RootViewController *rootViewController; @property (nonatomic, retain) DetailViewController *detailViewController; @end 

这是我绝望的尝试设置它

 - (id)initWithTabBar { self = [super init]; //this is the label on the tab button itself self.title = @"SplitView"; //use whatever image you want and add it to your project //self.tabBarItem.image = [UIImage imageNamed:@"name_gray.png"]; // set the long name shown in the navigation bar at the top self.navigationItem.title=@"Nav Title"; self.splitViewController = [[MGSplitViewController alloc] init]; self.rootViewController = [[RootViewController alloc] init]; self.detailViewController = [[DetailViewController alloc] init]; [self.splitViewController setDetailViewController:detailViewController]; [self.splitViewController setMasterViewController:rootViewController]; [self.view addSubview:splitViewController.view]; [self.rootViewController performSelector:@selector(selectFirstRow) withObject:nil afterDelay:0]; [self.detailViewController performSelector:@selector(configureView) withObject:nil afterDelay:0]; if (NO) { // whether to allow dragging the divider to move the split. splitViewController.splitWidth = 15.0; // make it wide enough to actually drag! splitViewController.allowsDraggingDivider = YES; } return self; } 

我想我在代表做错了什么? 或者我还有其他的东西混在一起? 演示是否在代码中看不到我在IB中做的事情? 我得到了分割视图,但没有内容,特别是没有导航栏与演示随附的button。

我会很感激提示或示例代码!

好的,曼尼,我们走吧。 这是我的界面的工作代码:

 #import <UIKit/UIKit.h> #import "MGSplitViewController.h" #import "ecbView.h" #import "ecbCalc.h" @interface splitMain : MGSplitViewController <UIPopoverControllerDelegate, MGSplitViewControllerDelegate> { IBOutlet UIPopoverController* popoverController; IBOutlet UINavigationController* naviController; IBOutlet ecbCalc* viewCalcLeft; IBOutlet ecbView* euroRatesRight; UIBarButtonItem* savedButtonItem; BOOL keepMasterInPortraitMode; BOOL memoryWasDropped; BOOL viewLoaded; } @property (nonatomic, retain) UIPopoverController* popoverController; @property (nonatomic, retain) UINavigationController* naviController; @property (nonatomic, retain) ecbCalc* viewCalcLeft; @property (nonatomic, retain) ecbView* euroRatesRight; @property (nonatomic, retain) UIBarButtonItem* savedButtonItem; @property (nonatomic, readonly) BOOL keepMasterInPortraitMode; @property (nonatomic, readonly) BOOL memoryWasDropped; @property (nonatomic, readonly) BOOL viewLoaded; - (void)dismissPopoverController: (BOOL)animated; - (void)settingsChanged; @end 

这里摘录了执行文件:

 - (id)initWithCoder:(NSCoder *)aDecoder { if ((self = [super initWithCoder:aDecoder])) { // my initialization... } return self; } // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { CGRect rectFrame = CGRectMake(0.0, 20.0, 768.0, 1004.0 - 48.0); // being above a tab bar! viewLoaded = NO; self.view = [[UIView alloc] initWithFrame:rectFrame]; viewCalcLeft = [[ecbCalc alloc] initWithNibName:@"ecbCalc" bundle:nil]; euroRatesRight = [[ecbView alloc] initWithNibName:@"ecbView-iPad" bundle:nil]; naviController = [[UINavigationController alloc] initWithRootViewController:self.viewCalcLeft]; naviController.navigationBar.barStyle = UIBarStyleBlack; naviController.title = nil; viewCalcLeft.title = NSLocalizedString(@"BtnTitleCalc", @""); viewCalcLeft.view.hidden = NO; NSUserDefaults* prefs = [NSUserDefaults standardUserDefaults]; if ([prefs objectForKey:@"iPadAlwaysSplitTableView"] != nil) self.keepMasterInPortraitMode = [prefs boolForKey:@"iPadAlwaysSplitTableView"]; else self.keepMasterInPortraitMode = YES; NSArray* theViewControllers = [NSArray arrayWithObjects:self.naviController, self.euroRatesRight, nil]; [self setViewControllers:theViewControllers]; [self setDelegate:self]; [self setShowsMasterInPortrait:keepMasterInPortraitMode]; } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { // protection because this one is called twice if (viewLoaded) return; [super viewDidLoad]; if (memoryWasDropped) { if (!self.keepMasterInPortraitMode && UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) { // recreate popover controller self.popoverController = [[UIPopoverController alloc] initWithContentViewController:self.viewCalcLeft]; } } viewLoaded = YES; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; memoryWasDropped = YES; // Release any cached data, images, etc. that aren't in use. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // eg self.myOutlet = nil; [self dismissPopoverController:NO]; self.popoverController = nil; self.naviController = nil; self.viewCalcLeft = nil; self.euroRatesRight = nil; viewLoaded = NO; } 

我的MainWindow.xib有一个UITabBarController,splitMain的button是为这个类configuration的,但是有一个空的xib条目。 所以创build必须通过loadView去。 也许我可以做loadView中的viewDidLoad东西…但是,所以我不得不保护viewDidLoad被调用两次。 一旦视图从MGSplitViewController类实例化,loadView就会发生这种情况,因为initWithCoder正在调用[self setup] 。 在该函数中,使用self.view.bounds计算frame rect,以便再次调用viewDidLoad,因为该视图还不存在。 也许可以在MGSplitViewController.m中实现一个解决方法,但是我太懒了。

要在标签栏控制器上执行此操作,请确保提交在MGSplitViewController的git页面上发布的大部分更改。 祝你好运。