如何以编程方式创建选项卡栏并在其上添加按钮
我想在我的视图中以编程方式将按钮添加到我的选项卡栏...
我有导航控制器,但它不允许我添加这些按钮.. 在我看来,我想以编程方式创建......
i want to add buttons on to my tab bar programmatically in my view...
i am having navigation controller but it does not allow me to add these ..
i want to create programmatically in my view...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于选项卡栏控制器是一个容器视图控制器,可用于将应用程序划分为两个或多个不同的操作模式,因此大多数应用程序都将导航控制器作为选项卡栏控制器的子级。
苹果的立场是这样的:
这并不是说您不能以不同的方式做事...您遇到的主要问题是您已经在应用程序中放置了一个导航控制器,并且您希望以编程方式创建选项卡栏控制器。因此,我能看到这一点的唯一方法是,您不介意每次在导航控制器中更改屏幕时标签栏控制器是否发生变化。有些应用程序以这种方式工作。大多数没有。
如果我的上述假设是正确的,我建议您重新考虑您的代码,看看您是否想继续这条开发路线。如果是这样,您可以轻松创建选项卡栏控制器并将其附加到当前视图中。
以下是我用来为我的一个应用程序创建设置的代码:
在很多情况下,我觉得以编程方式完成所有操作会更容易。
希望这有帮助。
Since a tab bar controller is a container view controller that you use to divide your application into two or more distinct modes of operation, most apps have navigation controllers as children of tab bar controllers.
Apple's position is this:
That is not to say you cannot do things differently... The main question you have is that you have already placed a Nav Controller in the app and you want to create the tab bar controller programmatically. The only way I can therefore see this is that you don't mind if the tabbar controller changes each time you change screens within the Nav Controller. Some apps work this way. Most do not.
If my assumptions above are true I would suggest you rethink your code to see if you want to pursue this line of development. If so, you can easily create a tabbar controller and attach it within the current view.
Here is code I use to create my setup for one of my apps:
There are so many situations where I feel it is easier to do everything programatically.
Hope this helps.
您必须保留对选项卡栏控制器的引用。例如,您可以将其保留在应用程序委托中......
You have to keep a reference to the tab bar controller. For instance you might keep it in the App Delegate...