Ios 实时应用程序崩溃,EXC\u错误\u访问内核\u无效\u地址
我的live应用程序随机崩溃,无法复制。下面是代码。由于崩溃发生在第20行,这是一个出口,它似乎有一些错误与我的自定义文本字段。我想不出哪里出了问题。有什么帮助吗 Crashlytics日志 崩溃:com.apple.main-threadexc\u坏访问内核\u无效\u地址 0x00000002d37a1db0 代码Ios 实时应用程序崩溃,EXC\u错误\u访问内核\u无效\u地址,ios,swift,uiview,uitextfield,Ios,Swift,Uiview,Uitextfield,我的live应用程序随机崩溃,无法复制。下面是代码。由于崩溃发生在第20行,这是一个出口,它似乎有一些错误与我的自定义文本字段。我想不出哪里出了问题。有什么帮助吗 Crashlytics日志 崩溃:com.apple.main-threadexc\u坏访问内核\u无效\u地址 0x00000002d37a1db0 代码 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let c
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
tableView.deselectRow(at: indexPath, animated: true)
let menu = menuItems[indexPath.row]
let menuTitle = menu.menuTitle
switch menuTitle{
case "My Profile":
performSegue(withIdentifier: "myProfileSegue", sender: cell)
//....
}
}
class ProfileViewController: UIViewController {
// ..
@IBOutlet weak var emailTextField: CustomTextField! // Line no. 20
}
class CustomTextField: UITextField {
var bottomBorder = UIView()
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func awakeFromNib() {
super.awakeFromNib()
self.initialize()
self.translatesAutoresizingMaskIntoConstraints = false
bottomBorder = UIView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
bottomBorder.backgroundColor = .lightGreyColour
bottomBorder.translatesAutoresizingMaskIntoConstraints = false
addSubview(bottomBorder)
bottomBorder.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
bottomBorder.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
bottomBorder.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
bottomBorder.heightAnchor.constraint(equalToConstant: 1).isActive = true
}
func initialize() {
let clearButton = UIButton(frame: CGRect(x: 0, y: 0, width: 16, height: 16))
clearButton.setImage(UIImage(named: "Glyph/16x16/Clear")!, for: .normal)
self.rightView = clearButton
clearButton.addTarget(self, action: #selector(clearClicked), for: .touchUpInside)
self.clearButtonMode = .never
self.rightViewMode = .whileEditing
}
@objc func clearClicked(sender:UIButton) {
self.text = ""
self.bottomBorder.backgroundColor = .lightGreyColour
}
}
我一直在读,但还是不明白。是否可能是crashlytics中的崩溃?您的VC是如何实例化的?performSegue(带有标识符:“myProfileSegue”,发送方:cell)。我已经更新了我的问题,以显示它是如何实例化的。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
tableView.deselectRow(at: indexPath, animated: true)
let menu = menuItems[indexPath.row]
let menuTitle = menu.menuTitle
switch menuTitle{
case "My Profile":
performSegue(withIdentifier: "myProfileSegue", sender: cell)
//....
}
}
class ProfileViewController: UIViewController {
// ..
@IBOutlet weak var emailTextField: CustomTextField! // Line no. 20
}
class CustomTextField: UITextField {
var bottomBorder = UIView()
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func awakeFromNib() {
super.awakeFromNib()
self.initialize()
self.translatesAutoresizingMaskIntoConstraints = false
bottomBorder = UIView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
bottomBorder.backgroundColor = .lightGreyColour
bottomBorder.translatesAutoresizingMaskIntoConstraints = false
addSubview(bottomBorder)
bottomBorder.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
bottomBorder.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
bottomBorder.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
bottomBorder.heightAnchor.constraint(equalToConstant: 1).isActive = true
}
func initialize() {
let clearButton = UIButton(frame: CGRect(x: 0, y: 0, width: 16, height: 16))
clearButton.setImage(UIImage(named: "Glyph/16x16/Clear")!, for: .normal)
self.rightView = clearButton
clearButton.addTarget(self, action: #selector(clearClicked), for: .touchUpInside)
self.clearButtonMode = .never
self.rightViewMode = .whileEditing
}
@objc func clearClicked(sender:UIButton) {
self.text = ""
self.bottomBorder.backgroundColor = .lightGreyColour
}
}