gpt4 book ai didi

iphone - 使用 Storyboard View Controller 创建编程选项卡栏?

转载 作者:可可西里 更新时间:2023-11-01 03:06:05 26 4
gpt4 key购买 nike

我有一个以编程方式创建的标签栏,但我在初始化与 View 关联的 Storyboard时遇到了困难。

我能够在没有 Storyboard 的情况下在选项卡栏中成功加载 View (请参阅下面的代码),但 View 仅部分显示,因为一些 UI 组件在 Storyboard 中。

我的 Storyboard名称是 MainStoryboard,我将 Storyboard View 标识符设置为 SettingsViewController。

如何在下面的代码中为 SettingsViewController 初始化 Storyboard?

- (void)createTabBarItems {
tabBarController = [[UITabBarController alloc] init];

settingsViewController = [[SettingsViewController alloc] init];


UINavigationController *sett = [[[UINavigationController alloc]
initWithRootViewController: settingsViewController] autorelease];

[sett.tabBarItem setTitle:@"Settings"];
[sett.tabBarItem setImage:[UIImage imageNamed:@"settings.png"]];

[tabBarController setViewControllers:
[NSArray arrayWithObjects:sett, sett, sett, sett, nil]];
}

最佳答案

如果你想在 Storyboard中初始化 View Controller ,你必须使用 Storyboard方法而不是直接分配 View Controller :

// load the storyboard by name
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

// either one of the two, depending on if your view controller is the initial one
settingsViewController = [storyboard instantiateInitialViewController];
settingsViewController = [storyboard instantiateViewControllerWithIdentifier:@"SettingsViewController"];

关于iphone - 使用 Storyboard View Controller 创建编程选项卡栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8113388/

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