ios - 将信息从集合视图传递到表视图
问题描述
现在我有一个表格视图,它是集合视图的扩展。
该应用程序的主要前提类似于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?
解决方案
据我了解,您想将name
价值传递给MapItemsTableViewController
?
您可以覆盖准备功能:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let viewController = segue.destination as! MapItemsTableViewController
viewController.name = // Data can input here
}
推荐阅读
- javascript - 将 react 渲染方法拆分为单独的 npm 包
- java - java.lang.NoClassDefFoundError:无法在 Windows 10 上初始化类 org.rocksdb.Options
- javascript - 如何使用 Ramda 将代码从 Lisp(MIT Schema)翻译成 JavaScript?
- c - 术语和代码线的平等
- angular - 角度清理变音符号的问题
- php - 使用 Angular.js 和 PHP 重新加载页面时获取空白页面
- python-3.x - 安装了熊猫但仍然无法导入它
- android - recyclerview 或 viewpager 上的 setRotationY(180) 在 Android 9(API 28)中创建滚动问题
- apache-flink - Apache Flink:从保存点启动作业时出现 AWS S3 超时异常
- xaml - 如何更改 BottomBarPage 中的工具栏背景颜色