【发布时间】:2020-09-21 13:33:28
【问题描述】:
现在我有一个表格视图,它是集合视图的扩展。
该应用程序的主要前提类似于 Apple Maps。我希望选择一个 collectionView 单元格,然后让 viewController 显示一个 tableView,其中包含该类别中所有受尊重的项目。
这是我的 collectionView 代码。
class ContentViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
let imageArray = [UIImage(named: "image 1"), UIImage(named: "image 2"), UIImage(named: "image 3")]
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imageArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell
cell.mapIconImage.image = imageArray[indexPath.row]
cell.mapIconLabel.text! = imageNameArray[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
performSegue(withIdentifier: "ShowTableViewPlaces", sender: self)
}
class CustomCell: UICollectionViewCell {
@IBOutlet weak var mapIconImage: UIImageView!
@IBOutlet weak var mapIconLabel: UILabel!
}
这是目前为止 tableView 的代码。
import UIKit
struct PlacesInTableView {
var name: String
init(name: String) {
self.name = name
}
}
class MapItemsTableViewController: UITableViewController {
var image1InTableView = [PlacesInTableView(name: "place 1"),
PlacesInTableView(name: "place 2"),
PlacesInTableView(name: "place 3")
]
var image2InTableView = [PlacesInTableView(name: "place 1")
]
var image3InTableView = [PlacesInTableView(name: "place 1"),
PlacesInTableView(name: "place 2")
]
选择收集视图时,我希望在该尊重的类别中的所有位置占据TableView的内容。我将如何将数据从集合视图单元格传递到新的 tableView?
【问题讨论】:
-
目前还不清楚该类别中受尊重的项目与集合视图的数据源数组有何关联。该代码包含一组图像和一个未知的
imageNameArray。顺便说一句,使用多个数组作为数据源是非常糟糕的做法,强烈建议不要这样做。 -
您对问题的解释不清楚。例如,“显示一个包含该类别中所有受尊重项目的 tableView”。 “类别”是什么意思?您只提到了集合视图。这与类别有什么关系?您是什么意思“受人尊敬的物品”(来自类别)?你能举一个类别和“受人尊敬的项目”的例子吗?
标签: ios swift xcode uitableview uicollectionview