2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CollectionViewの勉強

Last updated at Posted at 2014-05-01

githubでやれ案件。kobitoからの投稿テスト、twitterとの連携確認も兼ねて。

[Collection View Programming Guide](URL [https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/CollectionViews/CollectionViews.pdf) の実習メモ。サンプル通りだと思ったとおりの事ができないので、理解を深める意味も兼ねて3種類書いてみた。

  1. サンプル通りの実装
  2. 1を元にして、Interface Builderで定義していた Array Controllerをコードに移動し、bindもコードで書く
  3. さらに2を元にして、Collection Item Viewも Interface Builderから分離、コード上で CollectionViewと関連付ける。
  4. 3にアイテムの選択機能を追加。選択すると色が変わる。

ソース → https://github.com/Nunocky/CollectionViewStudy04

スクリーンショット

スクリーンショット 2014-05-01 10.58.09.png

オブジェクトの関連

どのサンプルもInterface Builderでどこまでやるかの違いだけで、使用するオブジェクトやその関連は一緒。サンプル2ではNSArrayControllerを、サンプル3では Collection View Itemを Interface Builderから切り離している。Interface Builder上で行っていたbindや itemPrototypeの関連付けは AppDelegateの applicationDidFinishedLaunchingで行っている。

Collection Viewの selectionIndexes, Collection View Itemの selectedプロパティへのbindはサンプル4のみ使っている。これは選択状態を取得・表示するためのもの。

CollectionViewStudyMemo.png

課題・TODO

この例ではアイテムの追加・削除・更新はサポートしていない。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?