如何在UITableView中显示2个自定义单元格

编程入门 行业动态 更新时间:2024-10-09 00:40:16
本文介绍了如何在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个自定义单元格

本文发布于:2023-11-23 00:49:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619518.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   单元格   如何在   UITableView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!