私は自分のView Controllerから値を渡そうとしているカスタムUICollectionViewCellを持っています。私はセルに画像を渡すことができますが、初期化時には何も表示されません。カスタムUICollectionViewCellに値を渡すにはどうすればよいですか?
ビュー・コントローラでの関連コード:カスタムセルクラスで
override func viewDidLoad() {
self.collectionView!.registerClass(MyCustomCell.self, forCellWithReuseIdentifier: "Cell")
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! MyCustomCell
cell.someValue = 5
cell.imageView.image = UIImage(named: "placeholder.png")
return cell
}
:
var someValue: Int!
var imageView: UIImageView!
override init(frame: CGRect) {
super.init(frame: frame)
imageView = UIImageView(frame: CGRectMake(0, 0, frame.width, frame.height))
contentView.addSubview(imageView)
let someValueLabel = UILabel()
someValueLabel.frame = CGRectMake(0, 75, 200, 30)
someValueLabel.text = "Value is: \(someValue)"
self.addSubview(someValueLabel)
}
イメージが正常にUICollectionViewから渡されたと私はそれを表示することができていますが、「someValueのさ'は常にゼロです。
私は間違っていますか?
また、UIImageViewプロパティ "imageView"を呼び出さないでください。 UITableViewCellには既にこの名前を使用しているものが含まれています。望ましくない影響をもたらす可能性があります。多分それは修正されましたが、私はすでにいくつかの問題に直面しています。このQのように:http://stackoverflow.com/questions/11681273/uitableviewcell-imageview-changing-on-select – BoilingLime