Привет У меня есть ViewController, у которого есть CollectionView внутри. и у меня возникли проблемы с настройкой настраиваемой ячейки представления в виде коллекции.Конфигурация Collection View Cell
Вот мой ViewController
import UIKit
class achievmentViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate , UICollectionViewDelegateFlowLayout{
@IBOutlet weak var progressBar: UIProgressView!
@IBOutlet weak var aCollectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
aCollectionView.delegate = self
aCollectionView.dataSource = self
aCollectionView.backgroundColor = UIColor.whiteColor()
aCollectionView.registerClass(achievmentViewCell.self, forCellWithReuseIdentifier: "achievmentCell")
let w = self.view.frame.width-40
let h = self.view.frame.height-72
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: h*(5/100), left: w*(3.1/100), bottom: h*(5/100), right: w*(3.1/100))
layout.itemSize = CGSize(width: w*(27/100), height: h*(30/100))
aCollectionView = UICollectionView(frame: CGRect(x: 20, y: 72, width: w, height: h), collectionViewLayout: layout)
// Do any additional setup after loading the view.
}
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 3
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell:achievmentViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("achievmentCell", forIndexPath: indexPath) as! achievmentViewCell
cell.backgroundColor = UIColor.greenColor()
cell.setTextForLabel("test")
cell.Label?.text = "test"
print(cell.Label?.text)
// cell.setImageForImageView(UIImage(named: "badge")!)
cell.imageView?.image = UIImage(named: "badge")!
return cell
}
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
}
А вот мой collectionViewCell Класс:
import UIKit
class achievmentViewCell: UICollectionViewCell{
@IBOutlet weak var Label: UILabel!
@IBOutlet weak var imageView: UIImageView!
}
И когда я запускаю их все я получил вид клеток, что ничего, но цвет фона. Еще раз помогите, пожалуйста, это для моего финала. Спасибо
Это все еще не работает :( –
все журналы Пробовали ли вы debbuging – adolfosrs
На самом деле это была какая-то проблема в раскадровке, что это позволит представление коллекции иметь другой класс контроллера:?. CollectionView и UICollectionView И я выбрал неправильно. –