ios - 从数组中获取文本到 UITableViewCell
问题描述
我是 Swift 编码的新手,我需要帮助。
我在将文本从 UITableViewCell 获取到另一个视图控制器时遇到了很大的问题。
我创建了一个数组,但它似乎没有复制到 UITableViewCell 中?
这是我的代码
导入 UIKit
var 容器 = likeViewController()
类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
}
}
解决方案
然后,您可以在您func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
的 VC 中创建新的 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
,您可以简单地呈现视图控制器。
self.present(selectionVC, animated: true, completion: nil)
推荐阅读
- python - 如果某些单词包含空格,则python正则表达式
- firebase - 如何渲染依赖 firebase 异步函数的组件?
- reactjs - antDesign中的select标签样式
- sql - SQL 查询仅在特定时间段内选择所有在职员工和终止员工
- string - PySpark:根据条件选择一列,其他列值匹配某些特定值,然后将匹配结果创建为新列
- google-admin-sdk - Api 创建用户 WEB_LOGIN_REQUIRED
- pytorch - RuntimeError:尝试反序列化 CUDA 设备上的对象,但 torch.cuda.is_available() 为 False
- python - 无法安装 MySQL-python
- python - 为什么返回 Int?Python
- angular - 是否可以以角度创建多页应用程序?