gpt4 book ai didi

swift - 如何在 Swift 的 Storyboard中将两个自定义单元格添加到 TableView 中?

转载 作者:可可西里 更新时间:2023-11-01 00:53:48 25 4
gpt4 key购买 nike

我有一个带有两个不同自定义单元格的 tableView。一个单元格有一个开关,另一个单元格有一个图像,我有两个单独的单元格自定义类,标识符..但我看不到这个。我不知道我是否需要将 Storyboard中的配置更改为动态或其他东西。我可以显示两个不同的自定义单元格

谢谢!

最佳答案

检查显示每个特定自定义单元格的标准,然后根据需要转换到该单元格:

override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {

if (criteria for cell 1) {
let cell = tableView!.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as? Cell1
return (cell)
}
else {
let cell = tableView!.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as? Cell2
return (cell)
}
}

swift 3

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath -> UITableViewCell {

if (criteria for cell 1) {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as! Cell1
return cell
}
else {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! Cell2
return cell
}
}

关于swift - 如何在 Swift 的 Storyboard中将两个自定义单元格添加到 TableView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25158615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com