I am new at Swift coding and i need help.
I am having a big problem getting text from a UITableViewCell to another viewcontroller.
I have created an array but it dont seem to copy into the UITableViewCell?
this is my code
import UIKit
var container = likedViewController()
class likedViewController: 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) {
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. self.present(selectionVC, animated: true, completion: nil)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.