gpt4 book ai didi

ios - Swift - 从带有选定单元格文本的静态 UITableView 转入 (prepareForSegue)

转载 作者:行者123 更新时间:2023-11-28 11:22:14 24 4
gpt4 key购买 nike

我正尝试在 Swift 中完成以下任务,但需要一些帮助。

它是一个静态表,当一个单元格被选中时,我需要它来将该单元格的文本保存在一个变量中,并推送到我的下一个 View 。我正在使用 prepareForSegue 方法来执行此操作。通过向前传递先前的变量,我已经完成了所有工作,预计我会卡在这张 table 上。

在下面的代码中,变量 'key' 是我还想推进的其他内容。

谢谢。

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "methodToConductorMaterial") {
var svc = segue.destinationViewController as ConMatViewController;


svc.key2 = key + TEXT OF TABLE CELL


}
}

最佳答案

sender 参数是您的表格 View 单元格。所以将它转换到单元格并从中获取文本:

let cell = sender as UITableViewCell
let text = cell.textLabel.text

关于ios - Swift - 从带有选定单元格文本的静态 UITableView 转入 (prepareForSegue),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26815159/

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