gpt4 book ai didi

ios - 将信息从 TableView 传递到 View Controller 不是基于 indexPathForSelectedRow,而是基于所选单元格的标签文本?

转载 作者:搜寻专家 更新时间:2023-11-01 06:34:22 24 4
gpt4 key购买 nike

我在 UIViewController 中有一个 tableview,在 Main.storyboard 上,我有一个 show第一个 View Controller tableview 上的原型(prototype)单元格转到第二个 View Controller 。我有这段代码:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showTheSeriesPage"
{
let indexPath : NSIndexPath = self.theTableAyy.indexPathForSelectedRow! as NSIndexPath
var destViewController = segue.destination as! SeriesPageViewController
var randomTemporaryArray = dataAry[indexPath.row]

destViewController.sampleTitle = randomTemporaryArray.objectSeriesTitle
destViewController.sampleAuthor = randomTemporaryArray.objectSeriesAuthor
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}

它有效,但仅当 tableview 处于特定顺序并且基于 indexPath.row 时,而不是基于单元格本身的特定细节。如何设置它,使其不依赖于所选的 indexPath.row,而是依赖于单元格的标签文本?谢谢!

最佳答案

简短回答:不要那样做。您目前的做法是正确的。您应该有一个包含 TableView 中显示的信息的数据模型。当用户点击一个单元格时,您应该使用所选单元格的索引路径来查找模型中的条目,然后获取适合该条目的任何字符串。

单元格是 View 对象,您不应该使用它们来存储信息。

关于ios - 将信息从 TableView 传递到 View Controller 不是基于 indexPathForSelectedRow,而是基于所选单元格的标签文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43236654/

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