我有一个带有静态单元格的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
:
连接:
我做错了什么? 感谢。
答案 0 :(得分:0)
阅读错误消息,请不要发布代码图片。
在tableView:cellforRowAtIndexPath
方法的某个地方,有一个空数组,但您正在尝试访问索引为1的元素。
答案 1 :(得分:0)
您正在使用静态单元格。没有理由实施if (preg_match('/^\d{10}$/', $string)) {
//valid mobile
} else if (filter_var($string, FILTER_VALIDATE_EMAIL)) {
//valid email
} else {
//invalid
}
和numberOfSections
,因为这些是由故事板中的静态布局指定的。
因为您已实施:
numberOfRowsInSection
你告诉iOS每个部分都有override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
行,这是谎言。因此,iOS会尝试访问第一部分的第二行,并在数组索引超出范围时崩溃,因为该部分只有3
行。
所以,删除1
和numberOfSections
的实现,你应该好好去。