gpt4 book ai didi

iphone - 如何添加 splitViewController

转载 作者:行者123 更新时间:2023-11-29 10:53:57 25 4
gpt4 key购买 nike

在我的应用程序中(一个示例应用程序,一旦成功,将在我的应用程序中实现)我正在从我的 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 概念。所以当我从我的主页单击“联系”按钮时,我需要让 splitViewController 工作。所以任何人都可以帮我解决这个问题?

最佳答案

SplitViewController 应该位于应用程序的根目录。不要让 NavigationController 成为应用程序的 Root View Controller ,你应该让 SplitViewController 成为它的根。

我的建议:
1. 详细了解 SplitViewController。检查here .
2. 了解有关 ViewController 的更多信息。检查这个Programming Guide .

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com