无法使用Swift访问TabBar项的索引 [英] Unable to access index of tabBar item using swift
本文介绍了无法使用Swift访问TabBar项的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
环境:xcode 6GM,Language Swift.我正在xcode 6 beta2中使用此代码设置tabBar项目的图像颜色
Environment: xcode 6GM, Language Swift. I was setting image color of a tabBar item using this code in xcode 6 beta2
var cameraTab : UITabBarItem = self.tabBar.items[1] as UITabBarItem
但是现在在xcode 6GM中,它给出了错误.错误:[AnyObject]?没有名为下标"的成员
But now in xcode 6GM it is giving error. Error: [AnyObject]? does not have a member named 'subscript'
推荐答案
项是可选的-您可以执行以下操作:
items is Optional - you can do:
if let items = self.tabBar.items {
println("\(items[1])")
}
或
var cameraTab : UITabBarItem = self.tabBar.items![1] as UITabBarItem
这篇关于无法使用Swift访问TabBar项的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文