gpt4 book ai didi

ios - 使用 TableViewCell IndexPath 值执行 segue

转载 作者:行者123 更新时间:2023-11-30 11:29:17 25 4
gpt4 key购买 nike

我在 TableViewCell 中有一个 UIButton,我想在点击 UIButton 时执行 segue,但我需要知道执行 segue 时的 IndexPath.row 值。这里有更多详细信息:

enter image description here

我执行转场的代码块:

}else if(segue.identifier == "toChat"){
let chatController = segue.destination as! ChatViewController
chatController.employeeSender = self.employeeData
//Currently I have tried this, but indexPath comes nil
if let indexPath = tableView.indexPathForSelectedRow {
chatController.employeeReceiver = (self.searchController!.isActive) ? self.searchResults[indexPath.row] : self.employeeArray[indexPath.row]
print("Receiver Data\(self.employeeArray[indexPath.row].alias)")
}

}

谢谢,

最佳答案

你有两个选择

1) 简单

您可以在 cellForRowAtindexPath 中向按钮添加标签,当您点击按钮事件时,您可以使用它创建 indexPath

2) 创建 UIButton 的子类,并在其中拥有一个 IndexPath 属性。并在 cellForRow 中分配索引路径,现在您可以在点击按钮时访问 button.indexPath

不要忘记使用委托(delegate)或 Clouser 将事件传递给 View Controller

希望对你有帮助

关于ios - 使用 TableViewCell IndexPath 值执行 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50422693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com