Swift 显示章节标题时出现问题

Swift 显示章节标题时出现问题,swift,uitableview,Swift,Uitableview,以下是显示章节标题的代码: func tableView(tableView: UITableView!, titleForHeaderInSection section: Int) -> String!{ if section == 0 { return sections[0] } else if (section == 1){ return sections[1] } else {

以下是显示章节标题的代码:

func tableView(tableView: UITableView!, titleForHeaderInSection section: Int) -> String!{
        if section == 0 {
            return sections[0]
        } else if (section == 1){
            return sections[1]
        } else {
            return ""
        }
    }
我有一个名为sections的sections列表。但是这些标题并没有出现在模拟器上。谢谢

下面是一个示例,用于演示带有标题的tableView是如何工作的。将其复制/粘贴到您的游乐场上,并查看其工作原理:

导入UIKit 导入PlaygroundSupport 类ViewController:UITableViewController{ var节=[第1节、第2节、第3节] 覆盖tableView中的func NumberOfsection:UITableView->Int{ 节数 } 覆盖函数tableView\utableview:UITableView,titleForHeaderInSection节:Int->String{ 章节[章节] } } PlaygroundPage.current.SetLiveViewController PlaygroundPage.current.NeedsDefiniteExecution=true
您正在返回字符串您在哪里设置该字符串?仅当您使用自定义标题时才需要。我们需要更多的内容来帮助解决这个问题。这里:var sections=[Customer,Items,Add new]您的节标题是否使用自定义视图?发布与显示headerInSection相关的全部代码。您的Swift版本是什么,因为这不是当前的Swift版本方法。现在是func tableView\utableview:UITableView,titleForHeaderInSection:Int->String?vs func TableView TableView:UITableView!,标题标题标题部分:Int->String!{。如果你删除它,开始重写它,让自动完成帮助你?