プロジェクトをビルドすると、シミュレーターで画面が白く表示され (コレクション ビューは黒くなります)、表示したいセルも表示されません。
私は xcode6-beta6 を使用しています。これは ios (iPad) 用です。
そのため、コレクション ビューにラベルを設定しようとしています。私のストーリーボードには、内部にラベルを配置した1つのセルを持つコレクションビューだけのView Controllerがあります。ストーリー ボードとビュー コントローラー コードで識別子とタグが適切に設定されていることはわかっています。また、dataSource アウトレットとデリゲート アウトレットが適切にセットアップされていることもわかっています。私はこのチュートリアルに従っていますhttps://www.youtube.com/watch?v=jiiN9oFH3vEしかし、それはxcode 5とobjective-cにあるため、swift/xcode6で完全に異なるものがあるかどうかはわかりません私はしていません。
これが私のコードです
import UIKit
class FirstViewController: UIViewController,UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
var testArray:[String]!
override func viewDidLoad() {
super.viewDidLoad()
testArray = ["hello","world","hola","mmg","me","la"]
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView!) -> Int{
return 1
}
func collectionView(collectionView: UICollectionView!, numberOfItemsInSection section: Int) -> Int{
return testArray.count
}
func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell!{
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as FirstCollectionViewCell
var label = cell.viewWithTag(1) as UILabel
label.text = testArray[indexPath.row]
return cell
}
}