gpt4 book ai didi

ios - 从数组中获取文本到 UITableViewCell

转载 作者:行者123 更新时间:2023-12-01 15:52:14 25 4
gpt4 key购买 nike

我是 Swift 编码的新手,我需要帮助。

我在从 UITableViewCell 获取文本到另一个 View Controller 时遇到了一个大问题。

我创建了一个数组,但它似乎没有复制到 UITableViewCell 中?

这是我的代码

导入 UIKit

var container = likedViewController()

类 likedViewController: UIInputViewController, UITableViewDelegate, UITableViewDataSource, icebreakerData { func textChoice(字符串:字符串?){

var likedList: [String] = ["Hello there"]

@IBOutlet var tableView: UITableView!


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return likedList.count
}



func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

cell.textLabel!.text = likedList[indexPath.row]
return cell

}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)

let row = indexPath.row
self.textDocumentProxy.insertText(likedList[row])

}


//-----------------

func tableView(_ tableView: UITableView,
heightForRowAt indexPath: IndexPath) -> CGFloat {
// Make the first row larger to accommodate a custom cell.
return 80
}



@IBAction func ad(_ sender: Any) {
container = likedViewController()
container.likedList.append("I am another one")
print("I am working")
}


override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
tableView.dataSource = self
tableView.delegate = self
}
func hey (){
let selectionVC = storyboard?.instantiateViewController(withIdentifier: "KeyboardViewController") as? KeyboardViewController
selectionVC?.iceBreakerDataDelegate = self
}

最佳答案

在您的 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 中,您可以创建新的 VC 并将其推送到您的 UINavigationController。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)

let row = indexPath.row
self.textDocumentProxy.insertText(likedList[row])

// if this is your destination VC
let selectionVC = storyboard?.instantiateViewController(withIdentifier: "KeyboardViewController") as? KeyboardViewController

// hand over the data
selectionVC?.iceBreakerDataDelegate = self
navigationController?.pushViewController(selectionVC, animated: true)

}

如果您没有使用 NavigationController,您可以简单地呈现 viewcontroller。self.present(selectionVC, animated: true, completion: nil)

关于ios - 从数组中获取文本到 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62314867/

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