我有一个应用程序将导航到UISplitView (完全在另一个视图中),如下所示:
- (void) switchToMyDayView {
NSLog(@"Show My Day Screen");
if (self.myDayController.view.superview == nil) {
if (self.myDayController == nil) {
MyDayController *myController = [[MyDayController alloc] initWithNibName:@"MyDay" bundle:nil];
self.myDayController = myController;
[myController release];
}
[homeScreenController.view removeFromSuperview];
[self.view insertSubview:self.myDayController.view atIndex:0];
}
}这在主导航屏幕上完成。
现在,MyDayController有一个名为MyDay.xib的XIB,它包含以下项:
文件的所有者: MyDayController
第一应答者: UIResponder
分裂视图控制器
-导航控制器-导航条
所以,我需要更多的组件,我需要一个UITableViewController和一个UISplitViewControllerDelegate,对吗?
我打算在我的MyDayController中实现这些协议,这是一种标准吗?
所以,在上面的代码之后,我得到了一个错误:
-UIViewController _loadViewFromNibNamed:bundle:加载了"MyDay“nib,但未设置视图出口。
那么,如何使用UISplitViewController修复它呢?我知道UISplitViewController有一个视图属性,但是我不能在IB中使用它/连接它,可以吗?
非常感谢
标记
发布于 2010-12-09 06:28:13
您不应该必须将UISplitViewController子类化。在你的"MyDayController“类中有什么行为?UISplitViewController基本上只负责为您布局主视图和详细视图,因此您的职责是实现这些控制器。
如果拆分视图位于应用程序的顶层,则可以将其添加到应用程序的主窗口nib中。如果不是,只需按编程方式创建:
- (void) switchToMyDayView {
NSLog(@"Show My Day Screen");
if (self.myDayController == nil) {
YourMasterViewController *masterViewController = [[YourMasterViewController alloc] initWithNibName:@"MasterView" bundle:nil];
YourDetailViewController *detailViewController = [[YourDetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
UISplitViewController *myController = [[UISplitViewController alloc] init;
myController.viewControllers = [NSArray arrayWithObjects:masterViewController, detailViewController, nil];
[masterViewController release];
[detailViewController release];
self.myDayController = myController;
[myController release];
}
[homeScreenController.view removeFromSuperview];
[self.view insertSubview:self.myDayController.view atIndex:0];
}您也不需要对self.myDayController.view.superview == nil进行测试,因为它在self.myDayController == nil中是隐式的
发布于 2012-10-06 16:30:14
谢谢克里斯托弗·皮克斯莱。这个解决方案对我有效,但我必须修复你给我的东西。请看下面的代码。
委托文件
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
LeftViewController *leftViewController = [[LeftViewController alloc] init];// initWithNibName:@"LeftViewController" bundle:nil];
RightViewController *rightViewController = [[RightViewController alloc] initWithNibName:@"RightViewController" bundle:nil];
UISplitViewController *myController = [[UISplitViewController alloc] init];
myController.viewControllers = [NSArray arrayWithObjects:leftViewController, rightViewController, nil];
self.window.rootViewController = myController;
[self.window makeKeyAndVisible];
return YES;
}希望这能有所帮助。
发布于 2011-02-02 08:53:56
如果您希望在主导航控制器和详细导航控制器中创建,那么您可以这样做。
self.rootViewController=[[RootViewController alloc]init];
self.detailViewController=[[FirstDetailViewController alloc]init];
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
self.splitViewController.delegate=self.detailViewController;https://stackoverflow.com/questions/2854840
复制相似问题