UITabBar 模态视图控制器

发布于 2024-11-09 01:39:02 字数 2431 浏览 0 评论 0原文

我试图在另一个 TabBarController 之上呈现一个 TabBarController 。我的应用程序的 MainWindow.xib 如下所示:

Files Owner
First Responder
My App App Delegate
Window
TabBarContoller
    +TabBar
    +Nav Controller Subclass (a custom class)
        +Navigation Bar
        +Table View Contoller Subclass (custom class)
        +Tab Bar Item
    +Second View Controller (not yet hooked up)

我试图在 TableView 中单击某个项目时显示 xib 文件。这个 xib 文件有一个 TabBarController 作为它的主视图,但是当视图显示时,选项卡栏和导航栏都是不可见的。我用来显示它的代码是:

MyAppAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.customNavController presentModalViewController:customDetailEditViewController animated:YES];

如果我使用下面的代码将视图控制器推送到堆栈上,我会看到正确的导航栏,但显示根视图控制器中的 TabBar 而不是视图中的 TabBar已被推动。

[delegate.customNavController pushViewController:customDetailEditViewController animated:YES];

我什至尝试删除 TabBarController 并手动实现我自己的 TabBar 委托,但会发生相同的效果(没有 NavigationBar 或 TabBar,或者来自根 ViewController 的 NavigationBar/TabBar)。

编辑:我已将源代码上传到http://mi6.nu/tabcontroller.zip 。如果有更多 iOS 经验的人能够看一下,我将不胜感激。

EDIT2:到目前为止,我最接近的是在第一个标签栏中呈现一个模态视图控制器,所以我的视图看起来像这样:

NavigationBar  
[          ]
[          ] 
[---View---]
[          ] 
[          ] 
TabBar from the pushed view 
TabBar from the root view

为了实现这一点,我正在使用:

UITabBarController *tabBarController = [[UITabBarController alloc] init];

    UIViewController *directionsView = [[UIViewController alloc] init];
    txtDirections = [[UITextView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)]; 
    [directionsView.view addSubview:txtDirections];

    IconPickerViewController *iconPicker = [[IconPickerViewController alloc]init];
    tabBarController.viewControllers = [NSArray arrayWithObjects:recipeDetailEditViewController,directionsView,iconPicker, nil];
    [directionsView release];
    [iconPicker release];

    MyAppAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    [delegate.rootNavController presentModalViewController:recipeDetailEditViewController animated:YES];

但这只会使一切变得复杂,因为a)这并不理想,因为我有两个选项卡栏,b)所有控件(所有编辑控件)都需要位于TableViewController中,以便可以加载/保存它们的值以编辑项目。如果推送的视图可以处理加载/保存并显示在根选项卡的顶部,那就容易多了。

这肯定是可能的吗?

I'm trying to present a TabBarController on top of another TabBarController. My application's MainWindow.xib looks like this:

Files Owner
First Responder
My App App Delegate
Window
TabBarContoller
    +TabBar
    +Nav Controller Subclass (a custom class)
        +Navigation Bar
        +Table View Contoller Subclass (custom class)
        +Tab Bar Item
    +Second View Controller (not yet hooked up)

I'm trying to display a xib file when an item is clicked in the TableView. This xib file has a TabBarController as it's main view, but when the view displays, the tab bar and navigation bar are both invisible. The code I'm using to display it is:

MyAppAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.customNavController presentModalViewController:customDetailEditViewController animated:YES];

If I use the code below to push the view controller onto the stack, I see the correct navigation bar, but the TabBar from the root view controller is shown instead of the one from the view which has been pushed.

[delegate.customNavController pushViewController:customDetailEditViewController animated:YES];

I even tried removing the TabBarController and manually implementing my own TabBar delegates but the same effect occurs (either no NavigationBar or TabBar, or the NavigationBar/TabBar from the root ViewController).

EDIT: I've uploaded the source to http://mi6.nu/tabcontroller.zip . I'd really appreciate it if someone with a bt more experience with iOS could take a look.

EDIT2: The closest I've come so far is presenting a modal view controller inside the first tabbar, so my view looks like this:

NavigationBar  
[          ]
[          ] 
[---View---]
[          ] 
[          ] 
TabBar from the pushed view 
TabBar from the root view

To achieve this, I'm using:

UITabBarController *tabBarController = [[UITabBarController alloc] init];

    UIViewController *directionsView = [[UIViewController alloc] init];
    txtDirections = [[UITextView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)]; 
    [directionsView.view addSubview:txtDirections];

    IconPickerViewController *iconPicker = [[IconPickerViewController alloc]init];
    tabBarController.viewControllers = [NSArray arrayWithObjects:recipeDetailEditViewController,directionsView,iconPicker, nil];
    [directionsView release];
    [iconPicker release];

    MyAppAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    [delegate.rootNavController presentModalViewController:recipeDetailEditViewController animated:YES];

This just complicates everything though, since a) It's not ideal as I have two tabbars and b) all controls (all of the editing controls) need to be in the TableViewController so their values can be loaded/saved to edit items. It would be much easier if the pushed view could handle loading/saving and appear on top of the root tabs.

Surely this must be possible?

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

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

发布评论

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

评论(2

苍暮颜 2024-11-16 01:39:02

这绝对是一场噩梦,但我最终通过在单击添加按钮时从 TableViewController 中以模态方式呈现视图来实现它:

[delegate.rootController presentModalViewController:recipeDetailEditViewController animated:YES];

delegate.rootController 是根 TabBarController
我展示的 XIB 文件没有 TabBarController,而是有 UIView、导航栏和 TabBar。当从 NavigationController 内部以模态方式呈现时,这似乎有效。
窗口布局

This was an absolute nightmare, but I eventually got it working by presenting the view modally from the TableViewController when the add button is clicked:

[delegate.rootController presentModalViewController:recipeDetailEditViewController animated:YES];

delegate.rootController is the root TabBarController
The XIB file I'm presenting does not have a TabBarController, but rather a UIView, a Navigation bar and a TabBar. This appears to work when presented modally from inside a NavigationController.
Window Layout

童话 2024-11-16 01:39:02

为什么你把所有东西都放在 main.xib 中?
尝试将第二个选项卡栏移出主窗口 xib 并将其放入 customDetailEditViewController 内。

Why are you putting everything in your main.xib?
Try moving the second tab bar out of the main window xib and instead put it inside the customDetailEditViewController.

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