gpt4 book ai didi

ios - 在 secondViewController 中有 4 个 textField 。我想用 firstviewController Collection View 单元检查这个 textField 值

转载 作者:行者123 更新时间:2023-11-28 07:29:29 25 4
gpt4 key购买 nike

我的 FirstViewController 中有 Collection View ,我想将数据从 Collection View 单元格传递到下一个 secondViewController textField。有四个文本字段,我在 XIB 中设计了这个文本字段并加载到 secondViewController。基本上我必须将 textField 数据检查到数组中的 Collection View 单元格标签。

这是我的代码

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 委托(delegate):

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.
}

关于ios - 在 secondViewController 中有 4 个 textField 。我想用 firstviewController Collection View 单元检查这个 textField 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55327899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com