【发布时间】:2018-01-27 20:03:46
【问题描述】:
问题:我在complaintController 中有一个表格视图,其中有“打开”按钮。每当我按下打开按钮时,我都会使用该行的数据转到 DetailComplaintViewController,但是当我返回 ComplaintController 并选择不同的按钮时,我会看到与先前选择相同的数据。
注意 - 我在 tableView 的单元格中创建了一个 segue 按钮。
这是我用来从 ComplaintController 转到 DetailComplaintController 的代码。
var passRow = 0
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let billCell = tableView.dequeueReusableCell(withIdentifier: "complaintCell") as! ComplaintTableViewCell
billCell.openBtn.tag = indexPath.row
billCell.openBtn.addTarget(self, action: #selector(btnClicked), for: .touchUpInside)
return billCell
}
func btnClicked(sender: UIButton) {
passRow = sender.tag
print("Position......\(sender.tag)")
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let rVC = segue.destination as? DetailComplaintViewController
rVC?.issueType = self.complaintListArray[passRow].issueType
rVC?.issuedescription = self.complaintListArray[passRow].description
rVC?.issuedate = self.complaintListArray[passRow].issueDate
}
【问题讨论】:
-
你能更清楚地解释你所面临的问题吗?
-
即使我选择了不同的按钮,我之前选择的数据也会显示出来
-
好吧,这意味着即使您在单元格中选择了不同的打开按钮,您也会得到错误的数据?
-
是的,我得到了错误的数据
-
然后获取该行的索引路径并根据该行从数组中获取值并从 Prepareforsegue 方法发送