使用TabBar的基于导航的应用程序

3 navigation iphone tabbar

我有一个基于导航的应用程序,它显示了一个TableView,您可以在其中选择一个单元格,它会为您带来该单元格的"详细信息视图".我希望这个视图有一个TabBar,我可以在3个子视图之间进行选择.我在网上找到了几个解决方案,但没有一个非常有帮助.是否有专门的教程或是他们的源代码,说明如何做到这一点?谢谢

Bra*_*Guy 6

基本上您需要做的是将Tab View Controller推送到Navigation Controller的viewcontroller堆栈.

从一个全新的"基于导航的应用程序"模板开始.我在RootViewController.m中添加了以下方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Navigation logic may go here. Create and push another view controller.
UIViewController *viewOneViewController =   [[UIViewController alloc] init];
viewOneViewController.title = @"One";
viewOneViewController.view.backgroundColor = [UIColor redColor];

UIViewController *viewTwoViewController =   [[UIViewController alloc] init];
viewTwoViewController.title = @"Two";
viewTwoViewController.view.backgroundColor = [UIColor orangeColor];

UIViewController *viewThreeViewController = [[UIViewController alloc] init];
viewThreeViewController.title = @"Three";
viewThreeViewController.view.backgroundColor = [UIColor greenColor];

UITabBarController *anotherViewController = [[UITabBarController alloc] init];
anotherViewController.viewControllers = [NSArray arrayWithObjects:viewOneViewController, viewTwoViewController, viewThreeViewController, nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
Run Code Online (Sandbox Code Playgroud)

}

将此更改为25以测试:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 25;
}
Run Code Online (Sandbox Code Playgroud)

现在,当我构建并运行时,我将以基本方式看到您正在寻找的内容.完成此工作后,您要做的是将UIViewControllers更改为您创建的自定义子类,以保存每个视图的代码.(如果您还使用Interface Builder,请将init更改为initWithNibNamed :).

希望这可以帮助你顺利完成任务.