gpt4 book ai didi

ios - UITableViewCONtroller 中的快速多个单元格子类

转载 作者:搜寻专家 更新时间:2023-10-30 21:53:27 25 4
gpt4 key购买 nike

我正在尝试将多个子类添加到 UITableView 中。问题是它一直给我以下错误:

Type UITableVieCell does not conform to protocol NilLiteralConvertible

CellForRowAtIndexPath

override  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section == 0 {

let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell

cell.textLabel?.text = self.section1[indexPath.row]
cell.accessoryType = .DisclosureIndicator

return cell

} else if indexPath.section == 1 {

let cell = tableView.dequeueReusableCellWithIdentifier("SwitchViewCell", forIndexPath: indexPath) as SwitchViewCell

cell.cellLabel?.text = self.section2[indexPath.row]

return cell
}

return nil
}

最佳答案

你不能返回零。而不是默认返回空单元格。

    var cell :UITableViewCell!

switch (indexPath.row) {
case 0:
cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = self.section1[indexPath.row]
cell.accessoryType = .DisclosureIndicator
break;

case 1:
cell = tableView.dequeueReusableCellWithIdentifier("SwitchViewCell", forIndexPath: indexPath) as SwitchViewCell
(cell as SwitchViewCell).cellLabel?.text = self.section2[indexPath.row]
break;

default:
break;
}

return cell

确保你已经注册了nib

 self.tableView.registerNib(UINib(nibName: "SwitchViewCell", bundle: nil), forCellReuseIdentifier: "SwitchViewCell")

关于ios - UITableViewCONtroller 中的快速多个单元格子类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26140914/

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