私はUILabel
私のviewControllerの変数を持っています:class AwardsViewController: UICollectionViewController
。viewController変数をアダプタから変更しますか?
@IBOutlet var awardsCollectionView: UICollectionView! // The collection view
private var adapter = AwardsCollectionAdapter() // The adapter
awardsCollectionView.dataSource = adapter
awardsCollectionView.delegate = adapter
私は、ユーザーがコレクションビューセルの一つをクリックすると、ビューコントローラ内UILabel
を変更する、すなわち:のViewControllerのcollectionViewは次のように接続されます必要なすべてのコレクションビュー機能を持つアダプタを持っていますこの機能で:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
{
// ...change text of viewController's label
}
誰もが、私は、アダプタで、この関数内でビューコントローラ内の変数へのアクセスを取得する方法を知っていますか?ラベルはプログラマチックに追加されているため、ストーリーボードには表示されず、viewControllerクラスにスコープされています。
class AwardsViewController: UICollectionViewController {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
私に知らせてくれてありがとう、私はこれをかなり新しくしているので、これを学ぶことは本当に役に立ちます。 – MarksCode