繁体   English   中英

即使导入了UIKit,也可以使用未声明的类型'UITableViewSection'

[英]Use of undeclared type 'UITableViewSection' even though UIKit is imported

我正在尝试创建对TableView的静态部分的引用。 我控制 - 从文档大纲(“我的部分”,在第二个屏幕截图中突出显示)拖动部分到相关的代码文件,Xcode提供连接到新的UITableViewSection插座(“类型”字段预填充“UITableViewSection “):

创造出路

但后来Xcode立即抱怨告诉我它不知道UITableViewSection是什么:

在此输入图像描述

我已经进口了UIKit,所以不是这样。 我找不到UITableViewSection的任何文档。 它似乎不存在,但那么为什么Xcode会让我把它拖到文件中来创建一个插座?

您无法像这样声明UITableViewSection,因为没有可用该名称的类。 您可以通过创建自定义原型UITableViewCell来完成它,并可以使用它自定义节标题,如下所示 -

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let cell = self.tableView.dequeueReusableCell(withIdentifier: "SectionHeader") as! CustomHeaderUITableViewCell
    return cell
}

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 60
}

我尝试了同样的事情并发生了同样的错误。 我所做的不是在该部分创建一个插座,我在内容视图上创建了一个插座

@IBOutlet var editCountdownTableViewCell: UITableViewCell!

我正在创建它,因为我希望能够隐藏和显示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM