0
我的tableview中的每一行都有一個postID。我想獲得這個ID併發送到另一個視圖。TableView:如何從選定的行中獲取字符串?
我該怎麼做?
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)
}
感謝北斗星,你真了不起:) –
沒問題:-)不要忘記,以紀念該解決您的問題的答案;-) – Wain