【发布时间】:2016-09-19 05:26:21
【问题描述】:
viewcontroller 符合四种协议:
class transferResultsViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UITableViewDataSource, UITableViewDelegate {
}
UICollectionView 包含 4 个单元格:
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
还有一个简单的实现:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCellForTransferResults
// Labels of cells are set up here --> irrelevant for question
return cell
}
有一个 TableView 嵌套在 CollectionView 单元格中,有 1 个部分:
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
问题:nr。所有四个 collectionView 单元格中的 tableview 行数都可以通过数组访问:
let nrOfRowsArray = [2, 3, 2, 1] // e.g. the 1st collectionnviewcell has a tableview embedded that contains 2 row
如何为每个 collectionviewcell 返回 tableview 内的 numberOfRows?
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var numberOfRows = ? // How to store the correct value here?
return numberOfRows
}
让它返回正确的 cellForRowAtIndexPath?
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "identifier"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! nestedTableViewCell
// Labels of cells are set up here --> irrelevant for question
return cell
}
【问题讨论】:
标签: swift uitableview uicollectionview