Swift:如何从其他UI函数访问`UITableViewCell`

时间:2017-06-28 07:26:26

标签: swift uitableview

我有一个UITableView,里面有一些部分。在其中一个部分中,有一个UIDatePicker。我尝试将重置日期实现到我的datePicker,但我遇到了一些问题。我需要从cell.accessoryType访问UIDatePickerAction。在我的代码段下面:

@IBAction func datePickerClaimedAction(_ sender: UIDatePicker) {
    self.dateClaimedBy = datePickerClaimed.date
    self.labelDateClaimed.text = programProperties.showDateFormatter.string(from: datePickerClaimed.date)

    self.buttonDeleteDateClaimed.isHidden = false

    // some code to access `cell.accessory`
}

我读了一些关于此的问题,但它仍然不起作用。任何其他建议或答案对我有帮助。在此先感谢

1 个答案:

答案 0 :(得分:-1)

我解决了。

首先,我创建一个变量var indexRow: IndexPath?。然后。我从

投出indexPath

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { .. }功能。

我需要第2行第4行的单元格,所以我添加了一个案例:

if indexPath.section == 2 && indexPath.row == 4 { self.indexRow = indexPath }

在我的DatePicker Action中,我使用了这个

let cell = tableView(tableView, cellForRowAt: indexRow!)

因此,我可以访问特定单元格cell.accessoryType = .disclosureIndicator。在此先感谢