如何添加splitViewController

时间:2013-10-08 09:10:39

标签: iphone ios uiviewcontroller uisplitviewcontroller

在我的应用程序(一个示例应用程序,成功后,将在我的应用程序中实现)我将从我的Appdelegate移动到viewController。在我的ViewController.m中,我正在初始化一个SplitViewController。但是我的代码不起作用..我给了我的appDelegate和ViewController代码..

Appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = self.navigationController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

ViewController.m

- (void)viewDidLoad
{


[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}

-(IBAction)btnClick:(id)sender
{
PopMenuViewController *menuVC = [[PopMenuViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *menuNavController = [[UINavigationController alloc] initWithRootViewController:menuVC];

PopMenuDetailViewController *detailVC = [[PopMenuDetailViewController alloc] initWithNibName:@"PopMenuDetailViewController" bundle:nil];
UINavigationController *detailNavController = [[UINavigationController alloc] initWithRootViewController:detailVC];

menuVC.detailViewController = detailVC;

splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = @[menuNavController, detailNavController];

 //appdelegate.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 //appdelegate.window.rootViewController = self.splitViewController;

[appdelegate.window addSubview:self.splitViewController.view];
}

我没有在AppDelegate中提供此代码,因为在我的真实应用程序中,我只需要在我的联系人页面中实现splitviewcontroller概念..所以当我点击我的HOMEPAGE中的CONTACT按钮时,我需要让splitViewController工作..所以任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:2)

SplitViewController应该位于应用程序的根目录下。您应该将SplitViewController作为其根目录,而不是使应用程序的NavigationController根视图控制器。

我的建议:
1.了解有关SplitViewController的更多信息。检查here
2.了解有关ViewControllers的更多信息。请检查此Programming Guide