我有一个静态单元格的UITableViewController
,当我运行应用程序并单击导致它的按钮时,我在AppDelegate中收到一个SIGABRT信号。
我试图找到未使用的插座,但它没有用。
这是控制台日志:
UITableViewController代码:
import UIKit
import os.log
class SettingsTableViewController: UITableViewController {
// MARK: Properties
@IBOutlet weak var noteDisplayKindSwitch: UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
notedisplayKindSwitch.setOn(Settings._displaynotesAsNames, animated: false)
}
@IBAction func ChangeNoteDisplayKind(_ sender: UISwitch) {
Settings._displayNotesAsNames = sender.isOn
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
}
故事板中的UITableViewController
:
连接:
我究竟做错了什么?谢谢。
您正在使用静态单元格。没有理由实现numberOfSections
和numberOfRowsInSection
,因为它们是由Storyboard中的静态布局指定的。
因为你已经实现了:
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
你告诉iOS每个部分都有3
行,这是谎言。所以iOS尝试访问第一部分的第二行,并且数组索引超出范围崩溃,因为该部分只有1
行。
所以,删除numberOfSections
和numberOfRowsInSection
的实现,你应该好好去。
阅读错误消息,请不要发布代码图像。
在你的tableView:cellforRowAtIndexPath
方法的某个地方,有一个空数组,但你正试图访问索引1处的元素。