«Это» - все о сфере охвата. Каждая функция имеет свою собственную область действия, и поскольку все в JS является объектом, даже функция может хранить некоторые значения в себе, используя «this».
$('#a').click(function(){
console.log($(this).attr('href'));
});
Вам нужно установить нижнее ограничение на красное представление, чтобы автомакет мог растянуть ячейку после установки постоянного значения
extension ViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "c", for: indexPath) as! customcell
configure(cell: cell, indexPath: indexPath)
cell.redview.backgroundColor = .red
cell.selectionStyle = .none
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! customcell
cell.constraint.constant = data[indexPath.row] == "contracted" ? 30 : 200
data[indexPath.row] = data[indexPath.row] == "contracted" ? "expanded" : "contracted"
tableView.reloadData()
}
func configure(cell: customcell, indexPath: IndexPath) {
let data = self.data[indexPath.row]
if data == "expanded" {
cell.constraint.constant = 200
} else {
cell.constraint.constant = 30
}
cell.layoutIfNeeded()
}
}
Вызов ниже будет пересчитывать высоты.
[tableView beginUpdates];
[tableView endUpdates];
beginUpdates & endUpdates
превосходит ваше решение. Перезагрузка всей таблицы часто имеет другие серьезные последствия.layoutIfNeeded
в любом случае не требуется. – Sulthan 14 July 2018 в 16:37