【发布时间】:2014-11-22 00:11:53
【问题描述】:
像这样初始化我的 ViewController 类:
class ViewController: UIViewController {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// Create a dict of images for use with the UIView menu tab
var imageDict = [String:UIImage]()
imageDict["hudson_terrace"] = UIImage(named: "hudson_terrace")
imageDict["sky_room"] = UIImage(named: "sky_room")
imageDict["rivington"] = UIImage(named: "rivington")
imageDict["highline_ballroom"] = UIImage(named: "highline_ballroom")
imageDict["gansevoort_park_redroom"] = UIImage(named: "gansevoort_park_redroom")
imageDict["gansevoort_park_rooftop"] = UIImage(named: "gansevoort_park_rooftop")
imageDict["evr"] = UIImage(named: "evr")
}
后来在课堂上写了这个函数...
func addImageViews () {
// loop through imageDict and add all the images as UIView subviews of menuScrollView
for (venue_name, image) in self.imageDict {
}
}
我收到错误“ViewController”没有名为“imageDict”的成员。
不知道为什么 imageDict 在函数内部对我不可用。任何人都可以建议一个更好的地方来放置 dict 以及如何访问它?
【问题讨论】:
标签: ios dictionary swift uiviewcontroller