[英]How to set a click to expand on a table view cell in iOS?
我正在為 iOS 編寫一個應用程序,並有一個自定義單元格類,如下所示:
import UIKit
class cell: UITableViewCell {
@IBOutlet weak var NameLabel: UILabel!
@IBOutlet weak var DescriptionLabel: UILabel!
@IBOutlet weak var CreatorLabel: UILabel!
@IBOutlet weak var TypeLabel: UILabel!
@IBOutlet weak var LocationLabel: UILabel!
@IBOutlet weak var noneFoundLabel: UILabel!
}
這個自定義單元格在 tableview 中被引用如下:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let myCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! cell
//Do the stuff
}
通過調用數組的計數來迭代單元格並且工作正常。 無論如何,是否有這樣的單元格大小在顯示器上小一點,因此它只顯示名稱和描述,並且一旦單擊將展開以向用戶顯示其余信息。 然后一旦點擊關閉,它會再次崩潰?
很有可能。 您需要跟蹤擴展了哪些單元格。 將此信息添加到數據源使用的數據中。
實現heightForRowAtIndexPath
函數。 根據給定的indexPath
是否展開,返回適當的高度。
在您的cellForRowAtIndexPath
函數中,根據單元格是否展開來配置單元格。
實現didSelectRowAtIndexPath
函數。 切換給定indexPath
的擴展狀態並重新加載該索引路徑處的行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.