![](/img/trans.png)
[英]In Tableview, How to get the textview value of selected row in Objective C
[英]TableView: how to get a string from selected row?
我的表格視圖中的每一行都有一個postID。 我想獲取此ID並發送到另一個視圖。
我怎樣才能做到這一點?
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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.