本文介绍了如何在UITableView中显示2个自定义单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在表格中显示2个不同的单元格.我已经通过将原型设置到表中进行了尝试.但它仍显示原型表单元格必须具有重用标识符警告.
有人可以指导我解决此警告吗?
关注此链接:
重写func tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath)->UITableView {切换indexPath.section {案例0:返回tableView.dequeueReusableCellWithIdentifier("CustomCell1",forIndexPath:indexPath)情况1:返回tableView.dequeueReusableCellWithIdentifier("CustomCell2",forIndexPath:indexPath)休息:返回UITableViewCell()}}I have to show 2 different cells in a table. I have tried it by setting a prototype to a table. but it is still showing Prototype table cells must have reuse identifiers warning.
could someone please guide me to resolve this warning.
Followed this link: UITableview with more than One Custom Cells with Swift
解决方案You must set the Reuse Identifier for both prototype cells, and they must be different. Then in your cellForItemAtIndexPath method, you must dequeue the cells using the corresponding Reuse Identifier based on the indexPath given.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableView { switch indexPath.section { case 0: return tableView.dequeueReusableCellWithIdentifier("CustomCell1", forIndexPath: indexPath) case 1: return tableView.dequeueReusableCellWithIdentifier("CustomCell2", forIndexPath: indexPath) break: return UITableViewCell() } }
更多推荐
如何在UITableView中显示2个自定义单元格
发布评论