我正在尝试在另一个collectionView
内创建collectionViewCell
。我可以得到外collectionView
的单元格,但编译器没有执行内部单元格。我怎样才能得到这两个细胞?
P.S我是新人。
CollectionViewController类:
class CollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout{
@IBOutlet var collectionView1: UICollectionView!
var coll2 = CollectionViewCell()
override func viewDidLoad() {
super.viewDidLoad()
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: 150)
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)as! CollectionViewCell
cell.backgroundColor = UIColor.black
return cell
}
}
CollectionViewCell CLass:
class CollectionViewCell: UICollectionViewCell {
@IBOutlet var collectionView2: UICollectionView!
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: collectionView2.frame.width, height: 150)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell1 = collectionView.dequeueReusableCell(withReuseIdentifier: "cell2", for: indexPath)as! CollectionViewCell2
cell1.backgroundColor = UIColor.red
return cell1
}
答案 0 :(得分:1)
将内部集合视图的委托和数据源设置为第一个集合视图单元格。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
答案 1 :(得分:0)
string Url = "https://www.rottentomatoes.com/browse/dvd-all/?services=netflix_iw";
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlWeb().Load(Url);
IEnumerable<string> movieTitles = from movieNode in htmlDoc.DocumentNode.Descendants()
where movieNode.GetAttributeValue("class", "").Equals("movieTitle")
select movieNode.InnerHtml;
未设置CollectionViewCell
的原因是您未将collectionView2
的{{1}}和delegate
属性设置为dataSource
的实例collectionView2
。
我在CollectionViewCell
中创建了一个名为setupViews
的方法,以便在CollectionViewCell
中出现CollectionViewCell
时可以调用它,以便委托和dataSource正在设置得当。
CollectionViewController
class CollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: 150)
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)as! CollectionViewCell
cell.backgroundColor = UIColor.black
cell.setupViews() // added this call
return cell
}
}