如何在视图控制器中添加导航控制器和标签栏控制器?
我正在开发一个包含视图控制器的应用程序,因为我的前两页内容仅视图而不是选项卡栏。之后我使用此代码创建了运行时选项卡栏控制器,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为选项卡栏创建新类,并且在 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.