我不断收到 Thread 1: signal SIGABRT in Xcode
I keep getting Thread 1: signal SIGABRT in Xcode
我正在尝试为 iPhone 编写一个简单的猜测 swift 应用程序。代码运行成功,显示"Build Succeeded"。但是,我不断收到特定行的此消息:"Thread 1: signal SIGABRT".
该行包含 "num += Int( (rand()%4) + 1)",在操场上运行良好。
谁能告诉我如何解决这个问题?
import UIKit
class ViewController: UIViewController {
var num = 0
@IBOutlet var GuessField: UITextField!
@IBOutlet var ResultLabel: UILabel!
@IBOutlet var ScoreLabel: UILabel!
@IBAction func NewGameButton(sender: UIBarButtonItem) {
num += Int( (rand()%4) + 1)
/* Random numbers generated at num range from 1 to 4, which respectively
correspond to strings BMW, Mercedes, Lamborgini, and Ford. */
}
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.
}
@IBAction func ResultButton(sender: AnyObject) {
if GuessField.text == "BMW" {
if num == 1 {ResultLabel.text = "You Win!"}
else {ResultLabel.text = "Try Again!"}
}
if GuessField.text == "Mercedes" {
if num == 2 {ResultLabel.text = "You Win!"}
else {ResultLabel.text = "Try Again!"}
}
if GuessField.text == "Lamborgini" {
if num == 3 {ResultLabel.text = "You Win!"}
else {ResultLabel.text = "Try Again!"}
}
if GuessField.text == "Ford" {
if num == 4 {ResultLabel.text = "You Win!"}
else {ResultLabel.text = "Try Again!"}
}
}
}
试着说 num = Int( (rand()%4) + 1)
而不是 num += Int( (rand()%4) + 1)
如果您创建了一个控件并向视图控制器添加了一个插座连接,然后在从控件的连接中正确删除插座连接之前从页面中删除了控件,则会发生 "Thread 1: signal SIGABRT" 错误。我以前有同样的问题。也可能是说您的 class 不符合 KeyValueCoding 或其他内容。请确保在删除控件之前清除控件的所有连接。
我正在尝试为 iPhone 编写一个简单的猜测 swift 应用程序。代码运行成功,显示"Build Succeeded"。但是,我不断收到特定行的此消息:"Thread 1: signal SIGABRT".
该行包含 "num += Int( (rand()%4) + 1)",在操场上运行良好。
谁能告诉我如何解决这个问题?
import UIKit
class ViewController: UIViewController {
var num = 0
@IBOutlet var GuessField: UITextField!
@IBOutlet var ResultLabel: UILabel!
@IBOutlet var ScoreLabel: UILabel!
@IBAction func NewGameButton(sender: UIBarButtonItem) {
num += Int( (rand()%4) + 1)
/* Random numbers generated at num range from 1 to 4, which respectively
correspond to strings BMW, Mercedes, Lamborgini, and Ford. */
}
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.
}
@IBAction func ResultButton(sender: AnyObject) {
if GuessField.text == "BMW" {
if num == 1 {ResultLabel.text = "You Win!"}
else {ResultLabel.text = "Try Again!"}
}
if GuessField.text == "Mercedes" {
if num == 2 {ResultLabel.text = "You Win!"}
else {ResultLabel.text = "Try Again!"}
}
if GuessField.text == "Lamborgini" {
if num == 3 {ResultLabel.text = "You Win!"}
else {ResultLabel.text = "Try Again!"}
}
if GuessField.text == "Ford" {
if num == 4 {ResultLabel.text = "You Win!"}
else {ResultLabel.text = "Try Again!"}
}
}
}
试着说 num = Int( (rand()%4) + 1)
而不是 num += Int( (rand()%4) + 1)
如果您创建了一个控件并向视图控制器添加了一个插座连接,然后在从控件的连接中正确删除插座连接之前从页面中删除了控件,则会发生 "Thread 1: signal SIGABRT" 错误。我以前有同样的问题。也可能是说您的 class 不符合 KeyValueCoding 或其他内容。请确保在删除控件之前清除控件的所有连接。