gpt4 book ai didi

ios - TableView : how to get a string from selected row?

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

我的 TableView 中的每一行都有一个 postID。我想得到这个 id 并发送到另一个 View 。

我该怎么做?

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! PostsTableViewCell
//get posts data
var rowData: NSDictionary = Posts[indexPath.row] as! NSDictionary
//get title
let title:String = rowData["post_title"] as! String
cell.posttitle.text = title
//get categorty
let category:String = rowData["category_name"] as! String
cell.postcategory.text = category
//get image
let imgurl = rowData["post_feature_image"] as! String
let realurl = root + imgurl
var imgURL: NSURL = NSURL(string: realurl)!
let imgData = NSData(contentsOfURL: imgURL)
cell.fimg.image = UIImage(data: imgData!)
// get post iD
var postID:String = rowData["post_id"] as! String
return cell
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let ccell = tableView.cellForRowAtIndexPath(indexPath)
let cid:String = ccell?.contentMode.rawValue(String: postID)
}

最佳答案

使用数据模型,而不是单元格

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var rowData: NSDictionary = Posts[indexPath.row] as! NSDictionary
let cid:String = rowData["post_id"] as! String
}

关于ios - TableView : how to get a string from selected row?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30505326/

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