在其他函数中访问表视图的属性

问题描述 投票:0回答:1

如何在该类的另一个函数中访问表视图函数的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)
}
ios swift
1个回答
0
投票

在函数范围之外声明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)

}
© www.soinside.com 2019 - 2024. All rights reserved.