iPhone - 标签栏 +查看问题

发布于 2024-08-06 07:48:53 字数 1060 浏览 2 评论 0原文

我在我的视图之一中使用库中的 UITabBar 控件(请注意,我没有使用 UITabBarController 而是 UITabBar 控件)。

现在,我向该 tabBar 添加两个 tabBar 项目。

我已经为此视图(.m 和 .h)文件创建了控制器类,并在 .h 文件中使用了委托。

在 .m 文件中,我使用了以下函数:

  • (void)tabBar:(UITabBar *)TabBarControl didSelectItem:(UITabBarItem *)FirstView

我已将 tag = 0 和 tag = 1 分配给相应的 tabBar 项目。

我想要做的是,单击第一个 tabBar 项目时我想显示一个视图,单击另一个 tabBar 项目时我想显示另一个视图。

因此,在上面的函数中,我检查如果单击的 tabBar 项目的标签为 0,我将显示一个视图,否则我将显示另一个视图。

我显示的视图如下:

Team1Scoreboard *tempTeam1Scoreboard = [Team1Scoreboard alloc]; tempTeam1Scoreboard = [tempTeam1Scoreboard initWithNibName:@"UserTeamScoreboard" 包:[NSBundle mainBundle]];

    self.cntrlTeam1Scoreboard = tempTeam1Scoreboard;

    [tempTeam1Scoreboard release];

    UIView *theWindow = [self.view superview];
    [self.view removeFromSuperview];
    [theWindow addSubview:self.cntrlTeam1Scoreboard.view];

现在的问题是,当我单击任何 tabBar 项目时,它将加载正确的视图,但当我将视图添加到窗口本身时,tabBar 本身将消失。

请帮助我,以便我可以加载正确的视图,并且我的 tabBar 本身也是可见的。

I am using a UITabBar control from library in one of my view (note that I am not using UITabBarController but the UITabBar control).

Now, I am adding two tabBar items to this tabBar.

I have created controller class for this view (.m and .h) files and used delegates in the .h file.

In the .m file I have used the following function:

  • (void)tabBar:(UITabBar *)TabBarControl didSelectItem:(UITabBarItem *)FirstView

I have assigned tag = 0 and tag = 1 to respective tabBar items.

What I want to do is that, on click of first tabBar item I want to show a view and click of another tabBar item, I want to show another view.

So, in the above function I am checking that if the tag of clicked tabBar item is 0 than I will show one view else I will show another view.

I am showing the view as following:

Team1Scoreboard *tempTeam1Scoreboard = [Team1Scoreboard alloc];
tempTeam1Scoreboard = [tempTeam1Scoreboard initWithNibName:@"UserTeamScoreboard" bundle:[NSBundle mainBundle]];

    self.cntrlTeam1Scoreboard = tempTeam1Scoreboard;

    [tempTeam1Scoreboard release];

    UIView *theWindow = [self.view superview];
    [self.view removeFromSuperview];
    [theWindow addSubview:self.cntrlTeam1Scoreboard.view];

Now the problem is that, when I click on any of the tabBar item, it will load the correct view but the tabBar itself will be disappeared as I am adding the view to window itself.

Please help me so that I can load correct view and also my tabBar itself is visible.

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

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

发布评论

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

评论(1

吖咩 2024-08-13 07:48:53

TabBar 正在消失,因为它是视图的子级,然后您要向该视图添加新子级,并且新子级的大小与父级相同。这有道理吗?好的,这样看:

您有 ViewA,ViewA 有几个标签和一个 TabBar。 ViewA 由 ViewControllerA 管理。在 ViewControllerA 中,您正在创建 ViewB 的实例并调用 ViewControllerA.view addSubView:instanceOfViewB ,对吧?在此之前,您需要调整 ViewB 的大小。

尝试这样的事情:

ViewControllerB *viewControllerB = [[ViewControllerB alloc]initWithNibName:@"ViewB" bundle:nil];
CGRect frame = CGRectMake(self.view.frame.origin.x, 
                          self.view.frame.origin.y,
                          self.view.frame.size.width, 
                          self.view.frame.size.height - 40);
viewControllerB.view.frame = frame;
[self.view addSubview:viewB.viewControllerB];

基本上它应该接近你正在做的事情,但我将尺寸设置为小 40 px(无论你需要删除标签栏)。

The TabBar is disappearing because it's a child of the view which you are then adding a new child to and the new child is sized the same as the parent. Did that make sense? Ok, look at it this way:

You have ViewA and ViewA has a couple of labels and a TabBar. ViewA is managed by ViewControllerA. In ViewControllerA you are creating an instance of ViewB and calling ViewControllerA.view addSubView:instanceOfViewB, right? Before doing that, you will want to resize ViewB.

Try something like this:

ViewControllerB *viewControllerB = [[ViewControllerB alloc]initWithNibName:@"ViewB" bundle:nil];
CGRect frame = CGRectMake(self.view.frame.origin.x, 
                          self.view.frame.origin.y,
                          self.view.frame.size.width, 
                          self.view.frame.size.height - 40);
viewControllerB.view.frame = frame;
[self.view addSubview:viewB.viewControllerB];

Basically it should be close to what you are doing, but I'm setting the size to be 40 px less (whatever you need to remove the tab bar).

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