gpt4 book ai didi

iphone - 带有 TabBar 的基于导航的应用程序

转载 作者:行者123 更新时间:2023-12-03 19:32:54 24 4
gpt4 key购买 nike

我有一个基于导航的应用程序,它显示一个 TableView,您可以在其中选择一个单元格,然后它会将您带到该单元格的“详细信息 View ”。我希望这个 View 有一个 TabBar,我可以在其中在 3 个 subview 之间进行选择。我在网上找到了几个解决方案,但没有一个很有帮助。是否有专门针对此问题的教程,或者他们的源代码是否表明了如何完成此操作?谢谢

最佳答案

基本上,您需要做的是将选项卡 View Controller 推送到导航 Controller 的 View Controller 堆栈上。

从全新的“基于导航的应用程序”模板开始。我在 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];

}

将其更改为 25 进行测试:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 25;
}

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

希望这对您有所帮助。

关于iphone - 带有 TabBar 的基于导航的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/599200/

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