[英]Getting text from array to UITableViewCell
I am new at Swift coding and i need help.我是 Swift 编码的新手,我需要帮助。
I am having a big problem getting text from a UITableViewCell to another viewcontroller.我在将文本从 UITableViewCell 获取到另一个视图控制器时遇到了很大的问题。
I have created an array but it dont seem to copy into the UITableViewCell?我创建了一个数组,但它似乎没有复制到 UITableViewCell 中?
this is my code这是我的代码
import UIKit进口 UIKit
var container = likedViewController() var 容器 = likeViewController()
class likedViewController: UIInputViewController, UITableViewDelegate, UITableViewDataSource, icebreakerData { func textChoice(string: String?) { } class likeViewController: UIInputViewController, UITableViewDelegate, UITableViewDataSource, icebreakerData { func textChoice(string: String?) { }
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
}
} }
In your func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
, you can then create the new VC and push it to your UINavigationController.在您的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)
}
In case you are not using a NavigationController
, you can simply present viewcontroller.如果你没有使用NavigationController
,你可以简单地展示 viewcontroller。 self.present(selectionVC, animated: true, completion: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.