无法在 Xcode 中为 UITableViewController 设置自定义 class

Unable to set a custom class for UITableViewController in Xcode

Xcode 不会让我将我的 table 视图的自定义 class 设置为以下 class(当我在故事板上设置它时它确实不要让我,下拉菜单什么也没有。

The following is my swift file for my table view controller.

https://gist.github.com/JudeMolloy/139e91d8c45ebe3d6140139ffd68a339

这是我的故事板的图片:

谢谢。

检查你的class是否至少有这些方法:

//
//  MyCustomTableViewController.swift
//  Test Table
//
//  Created by shadowsheep on 17/02/2018.
//  Copyright © 2018 shadowsheep. All rights reserved.
//

import UIKit

class MyCustomTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }

}

使用这些基本存根,您肯定能够访问 UITableViewController 的控制器...

编辑 根据提供的新信息: 您必须 select UITableViewController 而不是 UiTableView。一旦 select 编辑了您的 UITableViewController,您就可以设置您的自定义控制器。

您会看到您select编辑了正确的 class,因为身份检查器上提供的浅灰色默认 class 是 UITableViewController

然后您可以在下拉菜单中找到您的自定义控制器。

在您提供的图片中,您select编辑了 UITableView,而不是视图控制器。

您不能将 UITableView 的自定义 class 设置为视图控制器。

确保您 select 故事板中的视图控制器。单击视图控制器上方栏中的黄色图标。然后你就可以设置自定义 class.

如果您想在控制器上设置自定义 class,您要选择的自定义 class 应该继承该控制器,在本例中为 UITableViewController

假设您要使用 ViewController 作为控制器自定义 class,将其父级设置为 UITableViewController

import UIKit

class ViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }


}

然后您可以在检查器选项卡的自定义 class 下拉列表中看到 ViewController