-6
我有這樣的代碼,但它總是顯示我:爲什麼我得到:類型「任何」無標會員
類型「任何」無標會員
我不不知道發生了什麼事。 謝謝你們提前,請給我解釋一下我做錯了什麼,因爲我不知道:(
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
}
}