ios - 在 secondViewController 中有 4 个 textField 。我想用 firstviewController 集合视图单元检查这个 textField 值
问题描述
我有集合视图,我FirstViewController
想将数据从集合视图单元格传递到下一个secondViewController
textField
。有四个文本字段,我在 XIB 中设计了这个文本字段并加载到secondViewController
. 基本上我必须检查 textField 数据到数组中的集合视图单元格标签。
这是我的代码
import UIKit
class BackUpWord{
var label: String
var index: String
init(label:String, index:String) {
self.label = label
self.index = index
}
}
class FirstViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
private var seed : Seed!
private var words : [String]!
var backupWords:[BackUpWord] = []
override func viewDidLoad() {
super.viewDidLoad()
cellIndex = 1
self.collectionView.isPagingEnabled = true
let entropy = Data.randomBytes(length: 32)
self.seed = Seed.init(entropy: entropy)!
words = self.seed.toBIP39Words()
var index = 1
for item in words! {
backupWords.append(BackUpWord.init(label: item, index: index.description))
index = index + 1
}
}
extension FirstViewController: UICollectionViewDelegate, UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// return backupWords.count/2
return words.count/2
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! LabelCollectionViewCell
let even = backupWords[indexPath.row*2]
let odd = backupWords[indexPath.row*2+1]
cell.backUpWordFirst.text = even.label
cell.backUPWordSecond.text = odd.label
cell.index.text = even.index
cell.index2.text = odd.index
return cell
}
}
解决方案
使用collectionView的didSelect委托:
func collectionView(UICollectionView, didSelectItemAt: IndexPath) {
var backupWord: BackUpWord = backupWords[indexPath.row]
let nextViewController = NextViewController = // Get next controller
// Assign values to nextViewController
// Push to next controller and assign values to textfields.
}
推荐阅读
- python-3.6 - 使用 1 行嵌套 for 循环在 2D 列表中操作(列表理解)
- c# - 如何隐藏 DataGridView 中的特定列
- javascript - Photoshop - 从堆栈/层次结构的底层开始循环?
- kubernetes - Openshift pods 缩减过程
- python - 将多行按列值合并为一行,并根据连接行数拆分为多个数据帧,用于多列
- spring-boot - zuul 忽略来自客户端的标头,但允许 zuul 过滤器 addZuulRequestHeader
- java - http方法如何在servlet中工作?
- wordpress - 卡在复杂的 wordpress .htaccess 文件中。如果我使用其他任何东西,网站会出现 404 错误并且不会保存新帖子或页面
- dialogflow-es - 无法从 Dialogflow Fulfillment 调用我自己的 API
- javascript - 如何在angular2项目中使用PanelSnap插件包