那麼,要解決這個問題,你只需要在你的單元格視圖中設置標籤和選擇器之間的固定垂直間距。看到這個截圖

則每次用戶點擊單元格,你只需重新加載表視圖與更新的高度細胞。這裏是源代碼:
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
fileprivate var cellExpanded = false
// MARK: - UITableView datasource & delegate
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "PickerCell")!
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return (cellExpanded) ? 260:44
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
cellExpanded = !cellExpanded
tableView.reloadData()
}
}
有辦法做到這一點。告訴我們你到目前爲止試過的東西以及你卡在哪裏。 – arunjos007
最簡單的方法是使用Autolay來定義單元格的高度。這意味着在單元格的內容和本身之間添加約束。然後當你想顯示你的選擇器時,改變一個約束的'constant'屬性,這樣該單元展開顯示選擇器。 – paulvs