【发布时间】:2017-07-19 21:28:44
【问题描述】:
我跟着 Ash Furrows 教程 collectionView inside tableView
我有一个 TableItem 类,它有一个 name 属性和一个 URL 数组。我有一个 tableView,里面有 collectionView。
我用可用的任何数量的 TableItems 垂直填充我的 tableview,我用 TableItem 类的数组内的任何数量的 url 水平填充我的 collectionView。
我不关心按下表格单元格然后获取信息,我希望数据同时显示在两个集合中。
如何拉取TableItem数据,并与tableView同时显示在collectionView中?
class TableItem{
var name: String?
var urlsForCollection: [URl] = []
}
var tableItems = [TableItem]()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableItems.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableCell", for: indexPath) as! TableCell
cell.textLabel.text = tableItems[indexPath.row].name
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//how do I return the urlsForCollection.count from each TableItem in tableItems
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionCell", for: indexPath) as! CollectionCell
//how can I access the urlsForCollection for each TableItem in tableItems
for url in urlsForCollection{
imageView.sd_setImage(with: url!)
}
return cell
}
【问题讨论】:
标签: ios swift uitableview uicollectionview nsindexpath