uiTabBar - 用于菜单而不是视图控件? (iPhone)
快速问题 - 我有我的“第一个视图”,这将是我的应用程序中的唯一视图。我已使用 Interface Builder 将 UITabBar 添加到此视图。我只是想用它作为菜单来控制滚动视图的内容。
例如,用户单击 UITabBar 中的第一个图标 - 我获取其标签,然后基于该标签将子视图添加到滚动视图。这工作正常......
但是,我一直在查看一些关于选项卡栏的教程,似乎 99% 的时间它们都用于控制视图。我只是想让它返回我的标签。
所以我的问题是:我所做的好吗?它可以用于简单地返回值而不是更改视图吗?如果这是常见/好的做法,我到底该如何引用它呢?
我可以获取所选项目标签,但实际上无法引用 uiTabBar 来选择第一个按钮。在我的 .h 文件中,我尝试为控制器指定 IBOutlet,但无法在 IB 中链接它。
感谢您提供任何信息!
quick question - I have my "first view" which is going to be the ONLY view in my application. I've added a UITabBar to this view using Interface Builder. I am simply wanting to use this as a menu to control the contents of a scroll view.
For example, the user clicks on the first icon in the UITabBar - I get its tag, then based on that, will add a subview to the scrollview. This is working ok....
...but, I have been viewing a few tutorials on tabbars and it seems that 99% of the time they are used to control views. I simply want it to return my tags.
So my question is this: is what I am doing ok?? Can it be used for simply returning a value rather than changing a view? If this is common/OK practice, how on earth do I reference it?
I can get the selected item tag, but cannot actually reference the uiTabBar to make the first button selected. In my .h file, I tried to specify an IBOutlet for the controller, but I cannot link this in IB.
thanks for any info!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要接收已单击选项卡栏项目的通知,您需要修改视图控制器以实现 UITabBarDelegate协议并为标签栏添加一个出口。为此,请将 MyViewController.h 中的声明修改为如下所示:
然后在 MyViewController.m 中实现
tabBar:didSelectItem
方法,如下所示:您还必须设置视图控制器作为IB中标签栏的委托。 (提示:将选项卡栏的“委托”出口连接到文件所有者)。
要从视图控制器访问选项卡栏,请使用
tabBar
属性并执行以下操作:至于这是否是一个好主意 - 为什么不呢?所有教程都显示了与 UITabBarContoller 一起使用的选项卡栏来切换视图,但它也被设计为作为独立控件运行。只要您不违反任何 HIG 规则,那么如何实现接口切换就取决于您。
To receive notifications that a tab bar item has been clicked you need to modify your view controller to implement the UITabBarDelegate protocol and add an outlet for the tab bar. To do this, modify your declaration in MyViewController.h to something like this:
Then implement the
tabBar:didSelectItem
method in MyViewController.m as follows:You must also set your view controller as the delegate of the tab bar in IB. (hint: connect up the 'delegate' outlet from the tab bar to File's Owner).
To access the tab bar from your view controller use the
tabBar
property and do things like:As to whether this is a good idea - why not? All the tutorials show a tab bar being used with a UITabBarContoller to switch views, but it is designed to operate as a stand-alone control as well. As long as you are not breaking any HIG rules then how you implement your interface switching is up to you.