尝试更改单元格的高度在点击它时包含 pickerview

Trying to change the height of cell contains pickerview when tapping it

我正在尝试通过更改单元格的高度并在选择器选择完成后返回正常大小来使包含 UIPickerView 的单元格在点击时展开以显示我的 PickerView 的更多区域。

当我点击单元格时,只有里面的 PickerView 被点击..所以我无法使用 HeightForRow 来更改单元格 height.Can 任何人都可以提供帮助!

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

       if (indexPath == [0,0])
        {
             return 150
        }else{
              return 70 
        }}

你可以尝试使用delegate

protocol HeightManager{
    func changeHeight(TableCustomCell)
}

class TableCustomCell: UITableViewCell {
    var delegate: HeightManager?

    @IBAction func expandCollapseClicked(_ sender: UIButton) {
        self.delegate?.changeHeight(sender:self)
    }
}

在VC

class viewController: UIViewController,HeightManager{

    override func viewDidLoad() {
        super.viewDidLoad()

    }


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

         let cell = areaSettTable.dequeueReusableCell(withIdentifier:CellIdentifier1) as! TableCustomCell

         cell.delegate = self

         return cell
    }

    func changeHeight(sender:TableCustomCell) {

      // change height here in say array of heights
       self.tableView.reloadData()

    }
}

如果设置picker.userInteractionEnabled = false,点击事件将发送到单元格。然后,您需要在该索引路径处重新加载 table(以调整单元格的大小),并 re-enable 选择器。