0
類
初始化我的ViewController類,像這樣:問題在我的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在函數內部不可用。任何人都可以提出一個更好的地方來放置字典和如何訪問它?