[英]Swift3 iOS -How to get Data from All IndexPaths from TableView Before Cell Is Pressed
I followed Ash Furrows tutorial collectionView inside tableView 我在tableView中关注了Ash Furrows教程collectionView
I have TableItem class that has a name property and an array of URLs. 我有具有名称属性和URL数组的TableItem类。 I have a tableView that has collectionView inside of it.
我有一个tableView里面有collectionView。
I vertically populate my tableview with the whatever amount of TableItems are available and I horizontally populate my collectionView with however many amount of urls that are inside the array from the TableItem class. 我用可用的任意数量的TableItem垂直填充tableview,然后用TableItem类的数组内部的任意数量的URL水平填充collectionView。
I'm not concerned with pressing a table cell and then getting the information, I want the data to be displayed simultaneously in both collections. 我不关心按下表格单元格然后获取信息,我希望在两个集合中同时显示数据。
How can I pull the TableItem data and display it in the collectionView at the same time as the tableView? 如何提取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
}
Like this: 像这样:
let tableItem = tableItems[indexPath.row] as! TableItem
for url in tableItem.urlsForCollection{
imageView.sd_setImage(with: url!)
}
Should work. 应该管用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.