![](/img/trans.png)
[英]How to align UITableViewCell to the bottom of the UITableView?
[英]How to load second UITableViewCell at the bottom of UITableView?
我有一個tableView
,它填充我稱之為“ TopCell
”的自定義 UITableViewCells。 一切都完美無缺。 但是,我想添加第二個自定義 UITableViewCell 以顯示在tableView
的底部。 讓我們稱之為“ BottomCell
”
我已經創建了BottomCell
並連接到它的自定義類。 就像我對“ TopCell
”所做的TopCell
底部單元格將僅顯示一次並且位於tableView
的底部。
下面是TopCell
的基本代碼。 那么如何集成BottomCell
呢?
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return myData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "TopCell", for: indexPath) as? TopCell else { return UITableViewCell() }
let topVal = indexPath.row + 1
let noVal = myData[indexPath.row].no ?? 0
cell.configureCell(top: topVal, no: noVal)
return cell
}
這是你要求的:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return myData.count+1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == myData.count {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "BottomCell", for: indexPath) as? BottomCell else { return UITableViewCell() }
return cell
}
guard let cell = tableView.dequeueReusableCell(withIdentifier: "TopCell", for: indexPath) as? TopCell else { return UITableViewCell() }
let topVal = indexPath.row + 1
let noVal = myData[indexPath.row].no ?? 0
cell.configureCell(top: topVal, no: noVal)
return cell
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.