【问题标题】:What does the tag SIGABRT mean in Swift?标签 SIGABRT 在 Swift 中是什么意思?
【发布时间】:2018-08-22 09:54:27
【问题描述】:

我是 Swift 新手,我正在尝试开发一个测验应用程序。当我尝试在我的 iPhone 上加载应用程序时,我在 AppDelegate 类中收到 SIGABRT 错误,然后手机上只有一个白屏。我怎样才能解决这个问题?我已经尝试清理代码,我删除并仔细检查了按钮和代码之间的链接(如另一个问题与这些答案所建议的那样),我仍然收到此错误。

下面是我的视图类

import UIKit
import Foundation

class ViewController: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
        updateQuestion()
    }

    //Label
    @IBOutlet weak var label: UILabel!
    @IBOutlet weak var scorelabel: UILabel!
    @IBOutlet weak var flagview: UIImageView!

    //Botones
    @IBOutlet var botona: UIButton!

    @IBOutlet var botonb: UIButton!

    @IBOutlet var botonc: UIButton!

    @IBOutlet var botond: UIButton!

    let allQuestions = QuestionBank()
    var questionNumber: Int = 0
    var score: Int = 0
    var selectedAnswer: Int = 0

    //Button
    @IBAction func boton(_ sender: UIButton) {
        if sender.tag == selectedAnswer {
            print("Correcto")
            score+=1
        }
        else {
         print("Incorrecto")
        }
        updateQuestion()
    }

    func updateQuestion(){
    flagview.image=UIImage(named:allQuestions.list[questionNumber].questionImage)
        label.text=allQuestions.list[questionNumber].question

        botona.setTitle(allQuestions.list[questionNumber].optionA, for: UIControlState.normal)

        botonb.setTitle(allQuestions.list[questionNumber].optionB, for: UIControlState.normal)

        botonc.setTitle(allQuestions.list[questionNumber].optionC, for: UIControlState.normal)

        botond.setTitle(allQuestions.list[questionNumber].optionD, for: UIControlState.normal)

        selectedAnswer = allQuestions.list[questionNumber].correctAnswer

        questionNumber += 1
    }

    func updateUI(){

    }

    func restartQuiz(){

    }


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

任何帮助都将不胜感激!先感谢您。

【问题讨论】:

  • 您很可能断开了IBOulet 之间的连接。您是否重命名了插座,而不是删除旧链接并重新连接?
  • 我确实重命名了一个按钮,如何跟踪当前和旧链接?

标签: ios swift xcode debugging


【解决方案1】:

最好看看你的 Xcode 控制台日志在说什么。通常,如果任何出口的链接断开,日志中会显示信息。

还要回答您关于如何在 Xcode 中针对您的 IBOutlets 和 IBAction 跟踪当前和旧链接的问题,左侧有一个点。如果被填满,说明outlet和action连接正确。

请注意,有时会出现 Xcode 问题,并且这些圆圈无法正确显示。只需在相关情节提要上单击一次,然后再单击 viewController 文件,您的所有链接都会正确反映。

【讨论】:

  • 2018-03-13 18:59:30.581221-0600 LabsFisica[19849:1694359] *** 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[ setValue :forUndefinedKey:]: 这个类不符合键值编码。 *** 第一次抛出调用堆栈:(0 CoreFoundation 0x0000000111a9c12b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010dda8f41 objc_exception_throw + 48 2 CoreFoundation 0x0000000111a9c079 -
  • 我可以从您共享的代码和崩溃报告中猜到,您有一个链接到 IBOutlet 按钮的按钮,该按钮不再存在(因为您可能已将其重命名)。您需要删除该按钮的现有连接并将其重新连接到重命名的 IBOutlet
【解决方案2】:

SIGABRT 表示应用程序调用了 abort()(故意崩溃)。要了解有关该问题的更多信息,您可以添加异常断点。为此,您需要转到断点导航器,单击“+”按钮和“添加异常断点

要了解有关可用调试工具的更多信息,建议您阅读Apple's Debug tool documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-31
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 1970-01-01
    • 2010-09-29
    • 1970-01-01
    相关资源
    最近更新 更多