伊塔巴尔和伊塔巴里特姆
我正在尝试将 UITabBarItems
添加到 UITabBar
而不是选项卡栏控制器。这是我尝试做的。当我调用 setItems 时它总是崩溃。任何人都可以指出什么问题吗?
My_Accounts *my_AccountsVC = [[My_Accounts alloc] init];
Payments *paymentsVC = [[Payments alloc] init];
Transfer *transferVC = [[Transfer alloc] init];
NSArray *VCArray = [[NSArray alloc] initWithObjects:my_AccountsVC,paymentsVC,transferVC, nil];
[self.tabbar setItems:VCArray];
谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您查看
items
,它需要一个UITabBarItem
数组,而不是您似乎正在传递的UIViewController
子类。您必须跟踪其他地方的视图控制器,并传递一个
UITabBarItem
数组,并在UITabBar
的委托中处理视图控制器。或者更好的是,使用
UITabBarController
。If you look at
items
, it takes an array ofUITabBarItem
s and notUIViewController
subclasses which you seem to be passing.You will have to keep track of the view controllers elsewhere and pass an array of
UITabBarItem
s and handle the view controllers in theUITabBar
's delegate.Or much better, use
UITabBarController
.我相信您误解了
UITabBarController
的工作原理(文档链接)。您必须使用viewControllers
属性将UIViewController
添加到UITabBarController
。最后一行应为:
[tabBarController setViewControllers:VCArray];
UITabBarController
的tabBar
属性是只读的。你不能这样设置。如果您有一个
UITabBar
(文档链接),没有UITabBarViewController
,那么您将需要使用以下方法:但是,这些项目不是 UIViewController!它们是
UITabBarItem
的实例(文档链接)。您可以通过将它们放入数组中来一次性设置所有这些,也可以为每个视图控制器设置它们。您可以使用多个系统项目(更多、收藏夹等),或者您可以使用– initWithTitle:image:tag:
创建自定义项目。I believe you are misunderstanding how a
UITabBarController
works (documentation link). You must add theUIViewController
s to theUITabBarController
using theviewControllers
property.The last line you have should read:
[tabBarController setViewControllers:VCArray];
The
tabBar
property of theUITabBarController
is read-only. You cannot set that.If you have a
UITabBar
(documentation link) without aUITabBarViewController
, then you will need to use the method:However, these items are not
UIViewController
s! They are instances ofUITabBarItem
(documentation link). You may set these all at once by putting them into an array, or you can set them per view controller. There are several system items you may use (More, Favorites, etc) or you may use– initWithTitle:image:tag:
to create a custom item.代码好像有错。我想
上面的行应该有 UITabBarItems 数组的参数。我猜你传递了 UIViewController 的项目。您应该创建 UITabbarItems 并在 setItems 方法中传递该数组。
你应该做如下的事情:
我不确定它会做什么,因为我总是使用 UITabBarController。希望这有帮助。
Code seems wrong. I guess
Above line should have parameter of Array of UITabBarItems. You passed items of UIViewController I guess. You should Create UITabbarItems and pass array of that in setItems method.
You should do something like below:
I am not sure what it will do as I am always using UITabBarController. Hope this help.