Я установил CollectionView Контроллер и получил все, что работает очень хорошо и прямо.Swift: Внедрение представления коллекции без контроллера просмотра коллекции
class CollectionController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
.
.
.
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as CollectionViewCell
cell.myTitle.text = self.titles[indexPath.row]
let imgName = "pic\(indexPath.row).jpg"
cell.myImage.image = UIImage(named: imgName)
return cell
}
}
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var myTitle: UILabel!
@IBOutlet weak var myImage: UIImageView!
}
Теперь я хотел бы сделать то же самое с только UICollectionView
(неUICollectionViewController
). Я реализовал свою коллекцию так же, но когда я запускаю свое приложение, никакие ячейки не отображаются.
class ViewController: UIViewController, UICollectionViewDelegateFlowLayout {
override func viewDidLoad() {
super.viewDidLoad()
// 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.
}
}
class CollectionView: UICollectionView, UICollectionViewDelegateFlowLayout {
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as CollectionViewCell
cell.myTitle.text = self.titles[indexPath.row]
let imgName = "pic\(indexPath.row).jpg"
cell.myImage.image = UIImage(named: imgName)
return cell
}
}
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var myTitle: UILabel!
@IBOutlet weak var myImage: UIImageView!
}
Мне нужно реализовать некоторые инициализации в моем ViewController
ли? Я предполагаю, что я что-то второстепенное здесь :(
* Я работаю с раскадровкой, так что мои клетки и т.д. генерируется там, а не кода отсутствую.
thaaaanks, в этом была проблема :)) – MMachinegun