我正在尝试制作与iPad上的电子邮件应用程序类似(但不完全类似)的东西。
具体来说,我想创建一个基于选项卡的应用程序,但每个选项卡都会向用户呈现不同的 UISplitView。
每个 UISplitView 都包含一个 Master 和一个 Detail 视图(显然)。
在每个 UISplitView 中,我希望Master 成为一个多级导航控制器,其中新的 UIViewController 被推入(或弹出)堆栈。UISplitView 中的这种类型的导航是应用程序类似于本机电子邮件应用程序的地方。
据我所知,唯一描述一个体面的“在 uitabbarcontroller 中的 splitviewcontroller”的地方是:UISplitViewController in a TabBar ( UITabBarController )? 我试图遵循公认的答案。
接受的解决方案似乎对我有用(即,我得到一个标签栏控制器,允许我在不同的 UISplitViews 之间切换)。
问题是我不知道如何使 UISplitView 的左侧成为多级导航控制器。
这是我在我的应用程序委托中使用的代码,用于创建初始的“标签栏控制器内部的拆分视图”(这与上述链接中的建议非常相似)。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSMutableArray *tabArray = [NSMutableArray array];
NSMutableArray *array = [NSMutableArray array];
UISplitViewController *splitViewController = [[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];
[splitViewController setViewControllers:array];
[tabArray addObject:splitViewController];
[splitViewController release];
array = [NSMutableArray array];
splitViewController = [[UISplitViewController alloc] init];
viewCont = [[Master2 alloc] initWithNibName:@"Master2" bundle:nil];
[array addObject:viewCont];
[viewCont release];
viewCont = [[Slave2 alloc] initWithNibName:@"Slave2" bundle:nil];
[array addObject:viewCont];
[viewCont release];
[splitViewController setViewControllers:array];
[tabArray addObject:splitViewController];
[splitViewController 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;
}
MainViewController类是一个 UIViewController,它包含以下方法:
- (IBAction)push_me:(id)sender {
M2 *m2 = [[[M2 alloc] initWithNibName:@"M2" bundle:nil] autorelease];
[self.navigationController pushViewController:m2 animated:YES];
}
此方法(通过界面生成器)附加到 MainViewController.xib 中的 UIButton 显然,上面的方法(push_me)应该创建第二个 UIViewController(称为 m2)并将 m2 推送到拆分视图左侧的视图中当 UIButton 被按下时。然而,当按钮被按下时它什么也不做(即使我可以告诉这个方法被调用了)。
想想我哪里出错了?
蒂亚!