如何更改视图控制器的类类型?

Bri*_*ure 1 xcode ios swift

我创建了一个新项目,ViewController.swift 是:

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud)

我在视图控制器中创建了一个表视图,所以我想将类类型更改为 UITableViewController,这是我所做的:

class ViewController: UITableViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud)

然后程序发出SIGABART信号,怎么了?

Dun*_*n C 5

欢迎来到 SO。

AUITableViewController是一只奇怪的野兽。它只能管理一个表视图,不能管理其他任何东西。如果您希望您的视图控制器管理不同视图(标签、按钮等以及表格视图)的组合,则将其设置为 normal UIViewController,而不是UITableViewController.

如果要将视图控制器更改为不同的类,您必须同时更改源文件中的类,然后在 Interface Builder 的“身份检查器”中选择视图控制器,并在那里更改它的类。这可能是你的程序崩溃的原因。