【发布时间】:2017-11-25 21:45:16
【问题描述】:
我有这段代码,但它总是显示给我:
类型 'Any' 没有下标成员
我不知道发生了什么。 提前谢谢你们,请解释我做错了什么,因为我不知道:(
import UIKit
class PicturesViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
var posts = NSDictionary()
override func viewDidLoad() {
super.viewDidLoad()
posts = ["username" : "Hello"]
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return posts.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! PostCollectionViewCell
cell.usernameLbl.text = posts[indexPath.row]!["username"] as? String
cell.PictureImg.image = UIImage(named: "ava.jpg")
return cell
}
}
【问题讨论】: