作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个 tableView
,它填充自定义 UITableViewCells,我称之为“TopCell
”。一切都完美无缺。但是,我想添加第二个自定义 UITableViewCell 以显示在 tableView
的底部。让我们称之为“BottomCell
”
我已经创建了 BottomCell
并连接到它的自定义类。就像我对“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
}
关于ios - 如何在 UITableView 的底部加载第二个 UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48582953/
我是一名优秀的程序员,十分优秀!