作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在 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/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!