如何将来自 UITabBar(不是 UITabBarController)的 UITabBar 项目连接到 IB 中的不同视图? [英] How do I connect UITabBar items from a UITabBar (not a UITabBarController) to different views in the IB?

查看:33
本文介绍了如何将来自 UITabBar(不是 UITabBarController)的 UITabBar 项目连接到 IB 中的不同视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 StoryBoard 项目,并在我的第一个视图中添加了一个 UITabBar 和一些 UITabBar 项目.我使用的是 UITabBar 而不是 UITabBarController 因为 UITabBar 需要垂直滚动,所以它位于 UIScrollView.我想将 UITabBar 项目连接到不同的 ViewControllers.我如何在界面构建器中执行此操作?

I’ve created a StoryBoard project and added a UITabBar to my first view and a few UITabBar items on it. I’m using a UITabBar and not a UITabBarController because the UITabBar needs to be scrollable vertically so it is inside a UIScrollView. I want to connect the UITabBar items to different ViewControllers. How do I do that inside the Interface builder?

使用 UITabBarController 和 IB 中的其他东西一样,它只是一个 Ctrl+拖动,但由于某种原因 UITabBar 的行为不同.我知道我需要实现的所有委托方法,但现在我只对如何将 UITabBar 项连接到视图感兴趣.

With UITabBarController it’s just a Ctrl+drag like everything else in the IB, but for some reason the UITabBar acts differently. I’m aware of all the delegation methods I need to implement, but for now I’m only interested on how to connect the UITabBar items to the views.

推荐答案

  1. UITabBar 项目 ctr+drag 到你的下一个 ViewController(选择样式推送,模态).
  2. 给你 UITabbarItem 标签.
  3. UITabBarDelegate 导入您的控制器.
  4. 添加以下委托方法

  1. From UITabBar item ctr+drag to your next ViewController (select style push, modal).
  2. Give you UITabbarItem tags.
  3. Import UITabBarDelegate to your Controller.
  4. Add following delegate method

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    if (item.tag==0) {
        [self performSegueWithIdentifier:@"Favorite" sender:nil];
    }
    else if (item.tag==1)
    {
       [self performSegueWithIdentifier:@"Item" sender:nil];
    }
}

  1. 为每个 segue 提供标识符.

您可以通过以下链接

但问题是 tabbar 不会出现在下一个 ViewController

but problem is that tabbar will not appear on next ViewController

这篇关于如何将来自 UITabBar(不是 UITabBarController)的 UITabBar 项目连接到 IB 中的不同视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆