如何在类的另一个函数中访问表视图函数的indexPath
值/参数?例如:如果我下面有以下代码,如何将indexPath
的值传递给下面的IBAction
?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
var index = dataSource[indexPath.row]
// HOW CAN I ACCESS THE VAR INDEX IN THE IBACTION BELOW
}
@IBAction func nextDay(_ sender: UIButton) {
cday -= 1
Main(currentDay: cday, compDay: comparingDay, cIndex: index)
}
在函数作用域之外声明index
变量:
var index: Any?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
index = dataSource[indexPath.row]
}
@IBAction func nextDay(_ sender: UIButton) {
cday -= 1
Main(currentDay: cday, compDay: comparingDay, cIndex: index)
}