建筑成功然后弹出"Thread 1: signal SIGABRT error"
Building success then "Thread 1: signal SIGABRT error" pops up
我正在初步构建计算器。目前,代码只是在用户点击时将数字和 Pi 打印到计算器的标签中。
1)车码
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var display: UILabel! = nil
var userIsInTheMiddleOfTypeing = false
@IBAction func touchDigit(_ sender: UIButton){
let digit = sender.currentTitle!
if userIsInTheMiddleOfTypeing {
let textCurrentlyInDisplay = display.text!
display.text = textCurrentlyInDisplay + digit
} else {
display.text = digit
}
userIsInTheMiddleOfTypeing = true
}
@IBAction func performOperation(_ sender: UIButton) {
userIsInTheMiddleOfTypeing = false
if let methematicalSymbol = sender.currentTitle {
if methematicalSymbol == "π" {
display.text = String(M_PI) // M_PI
}
}
}
}
2) UI
touchDigit函数链接到所有数字按钮,如下图所示。 display 是 UILable
而 performOperaton 是 PI 按钮
问题
当我构建代码时,Xcode首先告诉我构建成功,但是,在我做任何事情之前,弹出如下错误
错误日志(从调试区复制)
2016-07-28 19:30:30.215343 Calculator[11671:208157] bundleid: com.Jeffery.Calculator, enable_level: 0, persist_level: 0, propagate_with_activity: 0
2016-07-28 19:30:30.218796 Calculator[11671:208157] Created DB, header sequence number = 260
2016-07-28 19:30:30.767300 Calculator[11671:208178] subsystem: com.apple.UIKit, category: HIDEvents, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0
2016-07-28 19:30:31.022078 Calculator[11671:208157] Created DB, header sequence number = 260
2016-07-28 19:30:31.350380 Calculator[11671:208157] subsystem: com.apple.BaseBoard, category: MachPort, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0
2016-07-28 19:30:31.388363 Calculator[11671:208159] subsystem: com.apple.FrontBoard, category: Common, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
我认为这里有问题:'@IBOutlet 弱变量显示:UILabel! = 零'。当你用 'display' 属性 做某事时,你尝试用 nil 做。在声明 属性 后尝试删除 '= nil'。或者你可以覆盖视图控制器初始化方法,但对我来说,在这种情况下这是不好的方法。
我弄清楚了我的错误,PI 按钮有两个连接到 viewControler(我应该删除一个)。
我正在初步构建计算器。目前,代码只是在用户点击时将数字和 Pi 打印到计算器的标签中。
1)车码
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var display: UILabel! = nil
var userIsInTheMiddleOfTypeing = false
@IBAction func touchDigit(_ sender: UIButton){
let digit = sender.currentTitle!
if userIsInTheMiddleOfTypeing {
let textCurrentlyInDisplay = display.text!
display.text = textCurrentlyInDisplay + digit
} else {
display.text = digit
}
userIsInTheMiddleOfTypeing = true
}
@IBAction func performOperation(_ sender: UIButton) {
userIsInTheMiddleOfTypeing = false
if let methematicalSymbol = sender.currentTitle {
if methematicalSymbol == "π" {
display.text = String(M_PI) // M_PI
}
}
}
}
2) UI
touchDigit函数链接到所有数字按钮,如下图所示。 display 是 UILable
而 performOperaton 是 PI 按钮
问题
当我构建代码时,Xcode首先告诉我构建成功,但是,在我做任何事情之前,弹出如下错误
错误日志(从调试区复制)
2016-07-28 19:30:30.215343 Calculator[11671:208157] bundleid: com.Jeffery.Calculator, enable_level: 0, persist_level: 0, propagate_with_activity: 0
2016-07-28 19:30:30.218796 Calculator[11671:208157] Created DB, header sequence number = 260
2016-07-28 19:30:30.767300 Calculator[11671:208178] subsystem: com.apple.UIKit, category: HIDEvents, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0
2016-07-28 19:30:31.022078 Calculator[11671:208157] Created DB, header sequence number = 260
2016-07-28 19:30:31.350380 Calculator[11671:208157] subsystem: com.apple.BaseBoard, category: MachPort, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0
2016-07-28 19:30:31.388363 Calculator[11671:208159] subsystem: com.apple.FrontBoard, category: Common, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
我认为这里有问题:'@IBOutlet 弱变量显示:UILabel! = 零'。当你用 'display' 属性 做某事时,你尝试用 nil 做。在声明 属性 后尝试删除 '= nil'。或者你可以覆盖视图控制器初始化方法,但对我来说,在这种情况下这是不好的方法。
我弄清楚了我的错误,PI 按钮有两个连接到 viewControler(我应该删除一个)。