在我的应用程序(一个示例应用程序,一旦成功,将在我的应用程序中实现)中,我将从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概念即可。因此,当我单击主页上的CONTACT按钮时,我需要让splitViewController工作。这个?

最佳答案

SplitViewController应该在应用程序的根目录。代替使NavigationController成为应用程序的根视图控制器,您应该使SplitViewController成为其根。

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

关于iphone - 如何添加splitViewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19243528/

10-09 16:18