Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of undeclared type 'UITableViewSection' even though UIKit is imported

I'm trying to create a reference to my TableView's static section. I control-drag the section from the Document Outline ("My Section", highlighted in the second screenshot) into the associated code file and Xcode offers to connect to a new UITableViewSection outlet (the "Type" field was pre-filled with "UITableViewSection"):

Creating outlet

But then Xcode immediately complains telling me it doesn't know what UITableViewSection is:

enter image description here

I've imported UIKit, so that's not it. I can't find any documentation for UITableViewSection. It seems to not exist, but then why would Xcode let me drag it into the file to create an outlet?

like image 395
Mike Miller Avatar asked Feb 08 '18 17:02

Mike Miller


2 Answers

You can not declare UITableViewSection like that, as there as no class available with that name. You can do it simply by creating a custom prototype UITableViewCell and can use it custom section header like below-

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
}
like image 59
Boudhayan Avatar answered Nov 05 '22 15:11

Boudhayan


I tried the same thing and same error occured. What i did was instead of creating an outlet on the section, i created an outlet on the Content View

@IBOutlet var editCountdownTableViewCell: UITableViewCell!

I am creating it because i want to be able to hide and show.

like image 31
Joel Avatar answered Nov 05 '22 16:11

Joel