菜鸟教程小白 发表于 2022-12-12 16:52:20

iOS:在没有 UITabBarController 的情况下从用户界面实现 UITabBar


                                            <p><p>在我的应用程序中,我有一个 UIViewController,我希望在其中添加一个 UITabBar。所以我通过用户界面添加了它(到 UIViewController.xib 文件中),并在 UIViewController.h+m 文件中创建了 IUTabBar 和 UITabBarItems 的实例。在 xib 文件中,我能够将代码项连接到 xib 上的代码项(通过从文件所有者拖动到相关项并选择相关的 IBOutlet),但我似乎无法将按钮连接回写在上的 IBActions h+m 个文件。</p>

<p>在添加 UITabBar 之前,我使用 UIToolBar 并且在进行这些连接时没有问题。</p>

<p>谁能解释我做错了什么? </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您应该实现 <code>UITabBarDelegate</code> 协议(protocol) (<a href="http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITabBarDelegate_Protocol/Reference/Reference.html" rel="noreferrer noopener nofollow">documentation here</a>)。 </p>

<p>一旦你实现了这个协议(protocol),只需使用 <code>- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item</code> 方法来知道用户何时更改了一个选定项标签栏。在此方法的实现中,您必须检查选择了哪个项目,并基于此手动更改 View 的内容。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iOS:在没有 UITabBarController 的情况下从用户界面实现 UITabBar,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/6801148/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/6801148/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS:在没有 UITabBarController 的情况下从用户界面实现 UITabBar