[英]Swift3 iOS -How to get Data from All IndexPaths from TableView Before Cell Is Pressed
我在tableView中关注了Ash Furrows教程collectionView
我有具有名称属性和URL数组的TableItem类。 我有一个tableView里面有collectionView。
我用可用的任意数量的TableItem垂直填充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
}
像这样:
let tableItem = tableItems[indexPath.row] as! TableItem
for url in tableItem.urlsForCollection{
imageView.sd_setImage(with: url!)
}
应该管用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.