如何在视图控制器中添加导航控制器和标签栏控制器?

发布于 2024-12-04 09:55:41 字数 1502 浏览 0 评论 0原文

我正在开发一个包含视图控制器的应用程序,因为我的前两页内容仅视图而不是选项卡栏。之后我使用此代码创建了运行时选项卡栏控制器,

           UIViewController *viewcontroller1 = [[viewcontroller1 alloc] initWithNibName:@"viewcontroller1" bundle:nil];
            viewcontroller1.title = @"sometext";
            viewcontroller1.tabBarItem.image = [UIImage imageNamed:@"someimage.png"];

            UIViewController *viewcontroller2 = [[viewcontroller2 alloc] initWithNibName:@"viewcontroller2" bundle:nil];
            viewcontroller2.title = @"sometext";
            viewcontroller2.tabBarItem.image = [UIImage imageNamed:@"someimage.png"];

            tbc = [[UITabBarController alloc] initWithNibName:@"viewcontroller1" bundle:nil];
            tbc.viewControllers = [NSArray arrayWithObjects: viewcontroller1,viewcontroller2, nil];
            tbc.selectedViewController = viewcontroller1;

            ////    NSLog(@"Selected index = %d of %d", tbc.selectedIndex, [tbc.viewControllers count]);
            [self presentModalViewController:tbc animated:NO];  

它工作正常,但在我的第二个视图中我想要选项卡栏控制器和导航控制器两者。 所以在 viewcontroller2 中我已经实现了这样的代码,它给了我导航控制器,但它隐藏了标签栏控制器,

- (void)viewDidLoad 
{

    nvc = [[UINavigationController alloc] initWithRootViewController:[[viewcontroller2 alloc] initWithNibName:@"viewcontroller2" bundle:nil]];
    [self presentModalViewController:nvc animated:NO];
    [nvc release];

    [super viewDidLoad];
}

所以请帮助我做什么,这样我就可以同时获得标签栏控制器和标签栏控制器。这个viewcontroller2中的导航控制器。?? 请指导我。

I am developing one application which includes view controller because my first two pages content only view not tab-bar.after that i have created run time tab-bar controller using this code

           UIViewController *viewcontroller1 = [[viewcontroller1 alloc] initWithNibName:@"viewcontroller1" bundle:nil];
            viewcontroller1.title = @"sometext";
            viewcontroller1.tabBarItem.image = [UIImage imageNamed:@"someimage.png"];

            UIViewController *viewcontroller2 = [[viewcontroller2 alloc] initWithNibName:@"viewcontroller2" bundle:nil];
            viewcontroller2.title = @"sometext";
            viewcontroller2.tabBarItem.image = [UIImage imageNamed:@"someimage.png"];

            tbc = [[UITabBarController alloc] initWithNibName:@"viewcontroller1" bundle:nil];
            tbc.viewControllers = [NSArray arrayWithObjects: viewcontroller1,viewcontroller2, nil];
            tbc.selectedViewController = viewcontroller1;

            ////    NSLog(@"Selected index = %d of %d", tbc.selectedIndex, [tbc.viewControllers count]);
            [self presentModalViewController:tbc animated:NO];  

it is working properly but in my second view i want tab-bar controller and navigation-controller both.
so in viewcontroller2 i have implemented code like that it's giving me navigation controller but it's hiding tab-bar controller

- (void)viewDidLoad 
{

    nvc = [[UINavigationController alloc] initWithRootViewController:[[viewcontroller2 alloc] initWithNibName:@"viewcontroller2" bundle:nil]];
    [self presentModalViewController:nvc animated:NO];
    [nvc release];

    [super viewDidLoad];
}

so please help me what to i do so i can get both tab-bar controller & navigation-controller in this viewcontroller2.??
please guide me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧情别恋 2024-12-11 09:55:42

您可以为选项卡栏创建新类,并且在 UI 设计时您可以将导航控制器添加为选项卡并在导航控制器中设置视图。每当您想在该页面中添加选项卡控制器时,都会创建 tabbarcontroller 类对象的对象并将其添加到视图中。

You can create new class for tabbar and in UI Design time you can add navigation controller as tab and set view in navigation controller. Whenever you want add tabbar controller in that page create object of tabbarcontroller class object and add it on view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文