iOS:在没有 UITabBarController 的情况下从用户界面实现 UITabBar
在我的应用程序中,我有一个 UIViewController,我希望向其中添加 UITabBar。因此,我通过用户界面添加了它(添加到 UIViewController.xib 文件中),并在 UIViewController.h+m 文件中创建了 IUTabBar 和 UITabBarItems 的实例。在 xib 文件中,我能够将代码项连接到 xib 上的代码项(通过从文件所有者拖动到相关项目并选择相关 IBOutlet),但我似乎无法将按钮连接回写在 xib 上的 IBActions h+m 文件。
在添加 UITabBar 之前,我使用了 UIToolBar,并且在进行这些连接时没有任何问题。
谁能解释我做错了什么?
In my app I have a UIViewController to which I wish to add a UITabBar. So I have added it via User Interface (into the UIViewController.xib file) and created instances of the IUTabBar and the UITabBarItems within the UIViewController.h+m files. in the xib file I was able to connect the code items to the ones on the xib (by dragging from the File Owner to the relevant item and selecting the relevant IBOutlet) but I cannot seem to connect back the buttons to the IBActions written on the h+m files.
Before adding the UITabBar I worked with a UIToolBar and had no problem doing these connections.
Can anyone explain what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该实现
UITabBarDelegate
协议 (此处的文档)。实现此协议后,只需使用
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
方法即可了解用户何时更改选项卡栏的选定项目。在此方法的实现中,您必须检查选择了哪个项目,并根据该项目手动更改视图的内容。You should implement the
UITabBarDelegate
protocol (documentation here).Once you are implementing this protocol, just use the
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
method to know when a user changes the selected item of a tab bar. In this method's implementation, you will have to check which item is selected, and manually change your view's content based on that.// 禁用此
// 启用此
// Disable this
// Enable this