Привет,Пользовательские клетки - UICollectionView внутри UITableView
У меня есть UICollectionView встроенный в UITableView. Похоже, что этот учебник: http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell/
исключая! Я хочу иметь метки в каждом UICollectionViewCell, которые отображают их indexPath.row.
Проблема: Я не знаю, как подключиться к моей XIB с UICollectionViewCell - так как мой класс, называемый MainTableCollectionViewCell класс UITableViewCell (не класс UICollectionViewCell). Мне нужно, чтобы иметь возможность манипулировать метку клетки, с @IBoutlet, но он не будет подключаться сейчас, потому что я не могу подключить мой класс XIb
вот мой проект инспектор:
MainTableCollectionViewCell.xib - это моя коллекция Просмотреть Cell
MainTableCollectionView.xib - просто пустой одиночный вид
MainTableCollectionViewCellControler.swift
MainTableCollectionViewControler.swift
и вот мой код:
Фрагмент кода Cell:
class MainTableCollectionViewCell: UITableViewCell{
var collectionView: UICollectionView!
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
var layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.scrollDirection = UICollectionViewScrollDirection.Horizontal
self.collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
self.collectionView.registerNib(UINib(nibName: "MainTableCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: collectionViewCellIdentifier)
self.collectionView.showsHorizontalScrollIndicator = false
self.contentView.addSubview(self.collectionView)
}
// -----------somestuff like delegates passing and overriding layoutsubviews below - I didnt include it here, I can paste it if necessary-------------
Фрагмент кода контроллера (см мои комментарии в dequeueReusableCellWithReuseIdentifier):
class MainTableCollectionViewController: UITableViewController,UICollectionViewDataSource,UICollectionViewDelegate {
// @IBOutlet var labelText: UILabel!
override init(){
super.init(style: UITableViewStyle.Plain)
self.tableView.registerClass(MainTableCollectionViewCell.self, forCellReuseIdentifier: reuseTableViewCellIdentifier)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 15
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseCollectionViewCellIdentifier, forIndexPath: indexPath) as UICollectionViewCell
//I would like to be able to put something like
// cell.label.text ="indexPath.row" but I need the outlet
// active
return cell
}
Я не могу сделать это cell.textLabel? .text = String (indexPath.row) Это не работает, потому что у меня нет textLabel, определенного где угодно. Это моя проблема - я не знаю, как ее определить. Пробовал поместить @IBOutlet textLabel в контроллер Cell, но я не могу связать розетку с ярлыком в XIB. Это потому, что XIB с ячейкой не подключен к классу CellController в Инспекторе идентификации. А ТАКЖЕ! Я не могу подключить его там, так как мой XIB - это CollectionCell, а мой класс ячейки - UITableViewCell. – Ammo