我跟着這個程序建立一個表定製單元:https://github.com/awseeley/Custom-Table-Cell隱藏元素 - 斯威夫特
單擊單元格時,我試圖擴大細胞,並顯示不同的內容。
以下是我在我的視圖控制器:
var cellTapped:Bool = true
var currentRow = 0;
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//CODE TO BE RUN ON CELL TOUCH
let selectedRowIndex = indexPath
currentRow = selectedRowIndex.row
let cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! TblCell
cell.image.hidden = true
tableView.beginUpdates()
tableView.endUpdates()
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.row == currentRow {
if cellTapped == false {
cellTapped = true
return 141
} else {
cellTapped = false
return 70
}
}
return 70
}
單擊時的電池膨脹並再次點擊時收縮。但圖像並不隱藏。我如何讓圖像隱藏?當單元格被選中並且具有展開/摺疊效果時,是否有更好的方式顯示另一個自定義.xib文件?
謝謝,但這只是從單元格中永久移除圖像,我如何才能在單元格被選中時移除圖像,並在不再選擇單元格時顯示圖像? –
@KatieH你想在'tableView'上只隱藏一個單元格,或者每個單元格點擊時都會顯示/隱藏? –
我只想在單元格處於活動狀態時單擊/選擇它時隱藏圖像。當單元格不再被選中時,圖像應該再次出現。 –