单击表格单元格时,将变量值发送到下一个视图控制器 [英] Send variable value to next view controller when click a table cell
问题描述
我有两个表视图控制器
-
InvoiceList
视图控制器 -
InvoiceShow
视图控制器
code> didSelectRowAtIndexPath 方法获得选定的表格单元特定值
override func tableView (tableView:UITableView,didSelectRowAtIndexPath indexPath:NSIndexPath){
let rowObject = objects [indexPath.row]
let invoicehash = rowObject [hash_key]!
我需要发送 invoicehash $ c $当点击
InvoiceList
InvoiceShow
控制器我试着用 prepareForSegue
函数。但它不适用,因为它会在 didSelectRawAtIndexPath
函数之前触发。所以当我实现它时,给出了以前的点击事件变量值。
请帮我从 InvoiceShow
invoiceHash
code> controller 您将在 prepareForSegue
$ b
override func prepareForSegue(segue:UIStoryboardSegue,sender:AnyObject?){
let selectedIndexPath = self.tableView.indexPathForSelectedRow()!
let rowObject = objects [selectedIndexPath.row]
let invoiceHash = rowObject [hash_key]!
让invoiceShowViewController = segue.destinationViewController as! InvoiceShowViewController
//将invoiceHash设置为`InvoiceShowViewController`here
invoiceShowViewController.invoiceHash = invoiceHash
}
I have two table view controllers
InvoiceList
view controllerInvoiceShow
view controller
I use didSelectRowAtIndexPath
method as bellow to get selected table cell specific value
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let rowObject = objects[indexPath.row]
let invoicehash = rowObject["hash_key"]!
}
i need to send invoicehash
value to InvoiceShow
controller when click the table cell of InvoiceList
i tried to use prepareForSegue
function. but it is not applicable because it will trigger before the didSelectRawAtIndexPath
function. so when i implemented it, gives the previous click event variable value. not correct one.
Please help me to access invoiceHash
variable value from InvoiceShow
controller
You will get the selected cell in prepareForSegue
method itself.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let selectedIndexPath = self.tableView.indexPathForSelectedRow()!
let rowObject = objects[selectedIndexPath.row]
let invoiceHash = rowObject["hash_key"]!
let invoiceShowViewController = segue.destinationViewController as! InvoiceShowViewController
// Set invoiceHash to `InvoiceShowViewController ` here
invoiceShowViewController.invoiceHash = invoiceHash
}
这篇关于单击表格单元格时,将变量值发送到下一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!